#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int *arr2;
  int iter;
  int sum = 0;
  if (argc < 2) {
    printf("Need to provide some integers.\n");
    return EXIT_FAILURE;
  }
  arr2 = malloc(argc * sizeof(int));
  if (arr2 == NULL) {
    printf("malloc fails.\n");
    return EXIT_FAILURE;
  }
  for (iter = 1; iter < argc; iter++) {
    arr2[iter] = (int)strtol(argv[iter], NULL, 10);
  }
  printf("The sum of ");
  for (iter = 1; iter < argc; iter++) {
    printf("%d ", arr2[iter]);
    sum += arr2[iter];
  }
  printf("is %d.\n", sum);
  free(arr2);
  return EXIT_SUCCESS;
}


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,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1186 <main+0x46>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <main+0x14a>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c3 <main+0x83>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    128a <main+0x14a>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120b <main+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <main+0x8a>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1264 <main+0x124>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1220 <main+0xe0>
mov    -0x20(%rbp),%esi
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     116c <main+0x1c>
lea    0xebf(%rip),%rdi
jmp    1225 <main+0xd5>
mov    %rsi,%r14
mov    %edi,%ebp
lea    0x0(,%rbp,4),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     121e <main+0xce>
mov    %rax,%r15
mov    %ebp,%r12d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14,%rbx,8),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <main+0x50>
lea    0xe3c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
lea    0xe35(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r15,%rbx,4),%r13d
mov    %r14,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    %r13d,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11e0 <main+0x90>
lea    0xe0c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2dbc(%rip),%rax
jmp    1231 <main+0xe1>
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Need to provide some integers.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [15 x i8] c"malloc fails.\0A\00"
@.str.2 = [12 x i8] c"The sum of \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [8 x i8] c"is %d.\0A\00"
@EXIT_SUCCESS = global i32 0
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %3
br label %74
14: ; preds = %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i32* @malloc(i32 %18)
store i32* %19, i32** %6
%20 = load i32*, i32** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %74
25: ; preds = %14
store i32 1, i32* %7
br label %26
26: ; preds = %42, %25
%27 = load i32, i32* %7
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %45
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i64 @strtol(i8* %35, i32* null, i32 10)
%37 = trunc i64 %36 to i32
%38 = load i32*, i32** %6
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %30
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %26
45: ; preds = %26
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %7
br label %47
47: ; preds = %65, %45
%48 = load i32, i32* %7
%49 = load i32, i32* %4
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %68
51: ; preds = %47
%52 = load i32*, i32** %6
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
%56 = load i32, i32* %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = load i32*, i32** %6
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
%62 = load i32, i32* %61
%63 = load i32, i32* %8
%64 = add nsw i32 %63, %62
store i32 %64, i32* %8
br label %65
65: ; preds = %51
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %47
68: ; preds = %47
%69 = load i32, i32* %8
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %69)
%71 = load i32*, i32** %6
%72 = call i32 @free(i32* %71)
%73 = load i32, i32* @EXIT_SUCCESS
store i32 %73, i32* %3
br label %74
74: ; preds = %68, %22, %11
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str.2 = [12 x i8] c"The sum of \00"
@.str.3 = [4 x i8] c"%d \00"
@.str.4 = [8 x i8] c"is %d.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [14 x i8] c"malloc fails.\00"
@str.5 = [31 x i8] c"Need to provide some integers.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str.5, i64 0, i64 0))
br label %38
6: ; preds = %2
%7 = shl i32 %0, 2
%8 = tail call i32* @malloc(i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = zext i32 %0 to i64
br label %14
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %38
14: ; preds = %10, %14
%15 = phi i64 [ 1, %10 ], [ %21, %14 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i64 @strtol(i8* nocapture %17, i32* null, i32 10)
%19 = trunc i64 %18 to i32
%20 = getelementptr inbounds i32, i32* %8, i64 %15
store i32 %19, i32* %20
%21 = add nuw nsw i64 %15, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %14
23: ; preds = %14
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = zext i32 %0 to i64
br label %26
26: ; preds = %23, %26
%27 = phi i64 [ 1, %23 ], [ %33, %26 ]
%28 = phi i32 [ 0, %23 ], [ %32, %26 ]
%29 = getelementptr inbounds i32, i32* %8, i64 %27
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = add nsw i32 %30, %28
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %25
br i1 %34, label %35, label %26
35: ; preds = %26
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %32)
%37 = tail call i32 @free(i32* %8)
br label %38
38: ; preds = %35, %12, %4
%39 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %12 ], [ @EXIT_SUCCESS, %35 ]
%40 = load i32, i32* %39
ret i32 %40
}