#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, const char *argv[]) {
  int n;
  int sum = 0, odd = 1;
  printf("This program add first N odd numbers. N =\n");
  printf(" ? ");
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    sum += odd;
    odd += 2;
  }
  printf("Sum is : %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec8(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <main+0x83>
mov    -0x1c(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1177 <main+0x57>
mov    -0x18(%rbp),%esi
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xed8(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    117f <main+0x4f>
lea    (%rax,%rax,2),%ecx
lea    -0x1(%rax),%edx
add    $0xfffffffe,%eax
imul   %edx,%eax
and    $0xfffffffe,%eax
lea    (%rax,%rcx,1),%ebx
add    $0xfffffffe,%ebx
lea    0xe81(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [43 x i8] c"This program add first N odd numbers. N =\0A\00"
@.str.1 = [4 x i8] c" ? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"Sum is : %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
store i32 0, i32* %9
br label %13
13: ; preds = %23, %2
%14 = load i32, i32* %9
%15 = load i32, i32* %6
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = add nsw i32 %19, %18
store i32 %20, i32* %7
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 2
store i32 %22, i32* %8
br label %23
23: ; preds = %17
%24 = load i32, i32* %9
%25 = add nsw i32 %24, 1
store i32 %25, i32* %9
br label %13
26: ; preds = %13
%27 = load i32, i32* %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %27)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c" ? \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [13 x i8] c"Sum is : %d\0A\00"
@str = [42 x i8] c"This program add first N odd numbers. N =\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %2
%11 = mul i32 %8, 3
%12 = add nsw i32 %8, -1
%13 = add nsw i32 %8, -2
%14 = mul i32 %12, %13
%15 = and i32 %14, -2
%16 = add i32 %11, %15
%17 = add i32 %16, -2
br label %18
18: ; preds = %10, %2
%19 = phi i32 [ 0, %2 ], [ %17, %10 ]
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %19)
ret i32 0
}