Created
September 3, 2014 13:44
-
-
Save kiyoka/6defcaac328de7b51d4c to your computer and use it in GitHub Desktop.
simple loop program.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int total = 0; | |
volatile int i; | |
for( i = 0 ; i < (1000000 * 1000) ; i++ ) { | |
total += i+1; | |
} | |
printf( "total = %d\n", total ); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; ModuleID = 'loop.c' | |
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" | |
target triple = "x86_64-pc-linux-gnu" | |
@.str = private unnamed_addr constant [12 x i8] c"total = %d\0A\00", align 1 | |
define i32 @main() nounwind uwtable { | |
%1 = alloca i32, align 4 | |
%total = alloca i32, align 4 | |
%i = alloca i32, align 4 | |
store i32 0, i32* %1 | |
store i32 0, i32* %total, align 4 | |
store volatile i32 0, i32* %i, align 4 | |
br label %2 | |
; <label>:2 ; preds = %10, %0 | |
%3 = load volatile i32* %i, align 4 | |
%4 = icmp slt i32 %3, 1000000000 | |
br i1 %4, label %5, label %13 | |
; <label>:5 ; preds = %2 | |
%6 = load volatile i32* %i, align 4 | |
%7 = add nsw i32 %6, 1 | |
%8 = load i32* %total, align 4 | |
%9 = add nsw i32 %8, %7 | |
store i32 %9, i32* %total, align 4 | |
br label %10 | |
; <label>:10 ; preds = %5 | |
%11 = load volatile i32* %i, align 4 | |
%12 = add nsw i32 %11, 1 | |
store volatile i32 %12, i32* %i, align 4 | |
br label %2 | |
; <label>:13 ; preds = %2 | |
%14 = load i32* %total, align 4 | |
%15 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([12 x i8]* @.str, i32 0, i32 0), i32 %14) | |
ret i32 0 | |
} | |
declare i32 @printf(i8*, ...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment