#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 *);
void addition() {
  int n, total = 0, k = 0, number;
  printf("\nEnter the number of elements you want to add:");
  scanf("%d", &n);
  printf("Please enter %d numbers one by one: \n", n);
  while (k < n) {
    scanf("%d", &number);
    total = total + number;
    k = k + 1;
  }
  printf("Sum of %d numbers = %d \n", n, total);
}


x86 assembly (clang, -O0):
<addition>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee4(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x4(%rbp),%esi
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1198 <addition+0x78>
lea    0xeb7(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <addition+0x45>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addition>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xed2(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xef1(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%esi
lea    0xee2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%rsp),%esi
test   %esi,%esi
jle    1189 <addition+0x69>
xor    %ebp,%ebp
lea    0xec8(%rip),%r14
lea    0x4(%rsp),%r15
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <scanf@plt>
add    0x4(%rsp),%ebx
add    $0x1,%ebp
mov    (%rsp),%esi
cmp    %esi,%ebp
jl     1170 <addition+0x50>
lea    0xec8(%rip),%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"\0AEnter the number of elements you want to add:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Please enter %d numbers one by one: \0A\00"
@.str.3 = [25 x i8] c"Sum of %d numbers = %d \0A\00"
define void @addition() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %7)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %3
%11 = load i32, i32* %1
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %2
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
store i32 %17, i32* %2
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
br label %9
20: ; preds = %9
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %21, i32 %22)
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"\0AEnter the number of elements you want to add:\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [38 x i8] c"Please enter %d numbers one by one: \0A\00"
@.str.3 = [25 x i8] c"Sum of %d numbers = %d \0A\00"
define void @addition() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %1
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %0, %11
%12 = phi i32 [ %17, %11 ], [ 0, %0 ]
%13 = phi i32 [ %16, %11 ], [ 0, %0 ]
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%15 = load i32, i32* %2
%16 = add nsw i32 %15, %13
%17 = add nuw nsw i32 %12, 1
%18 = load i32, i32* %1
%19 = icmp slt i32 %17, %18
br i1 %19, label %11, label %20
20: ; preds = %11, %0
%21 = phi i32 [ 0, %0 ], [ %16, %11 ]
%22 = phi i32 [ %9, %0 ], [ %18, %11 ]
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 %21)
ret void
}