int MAIN() {
  int i, num1;
  int result = 0;
  write("enter a integer");
  num1 = read();
  for (i = 0; i < num1; i = i + 1) {
    result = result + i;
  }
  write(result);
  write("\n");
  return 0;
}


x86 assembly (clang, -O0):
<MAIN>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <write@plt>
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1171 <MAIN+0x51>
mov    -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    114e <MAIN+0x2e>
mov    -0xc(%rbp),%edi
mov    $0x0,%al
call   1030 <write@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MAIN>:
push   %rbx
lea    0xed8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <write@plt>
xor    %eax,%eax
call   1040 <read@plt>
test   %eax,%eax
jle    114f <MAIN+0x2f>
lea    -0x1(%rax),%ecx
lea    -0x2(%rax),%edx
imul   %rcx,%rdx
shr    %rdx
lea    (%rax,%rdx,1),%ebx
add    $0xffffffff,%ebx
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <write@plt>
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <write@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"enter a integer\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @MAIN() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = call i32 (i8*, ...) bitcast (i32 (...)* @write to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @read()
store i32 %5, i32* %2
store i32 0, i32* %1
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %1
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %6
%11 = load i32, i32* %3
%12 = load i32, i32* %1
%13 = add nsw i32 %11, %12
store i32 %13, i32* %3
br label %14
14: ; preds = %10
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %6
17: ; preds = %6
%18 = load i32, i32* %3
%19 = call i32 (i32, ...) bitcast (i32 (...)* @write to i32 (i32, ...)*)(i32 %18)
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @write to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"enter a integer\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @MAIN() {
%1 = tail call i32 (i8*, ...) bitcast (i32 (...)* @write to i32 (i8*, ...)*)(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (...) @read()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0
%5 = add nsw i32 %2, -1
%6 = zext i32 %5 to i33
%7 = add nsw i32 %2, -2
%8 = zext i32 %7 to i33
%9 = mul i33 %6, %8
%10 = lshr i33 %9, 1
%11 = trunc i33 %10 to i32
%12 = add i32 %2, %11
%13 = add i32 %12, -1
br label %14
14: ; preds = %4, %0
%15 = phi i32 [ 0, %0 ], [ %13, %4 ]
%16 = tail call i32 (i32, ...) bitcast (i32 (...)* @write to i32 (i32, ...)*)(i32 %15)
%17 = tail call i32 (i8*, ...) bitcast (i32 (...)* @write to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}