#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 */
long INT_MAX;
long INT_MIN;
int /*<<< orphan*/ printf(char *, ...);
long reliable_atol(char *);
void main(int argc, char **argv) {
  int lcv;
  long grandSum = 0;
  for (lcv = 1; lcv < argc; lcv++) {
    long n = reliable_atol(argv[lcv]);
    printf("Running total: %ld + ", grandSum);
    long sum = (long)((unsigned long)grandSum + (unsigned long)n);
    printf("%s = %ld \n", argv[lcv], sum);
    if (n > INT_MAX || n < INT_MIN) {
      printf("Numeric overflow, caused by: %ld\n", n);
    }
    grandSum = sum;
  }
  printf("Grand sum: %ld \n", grandSum);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11eb <main+0xcb>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <reliable_atol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
jg     11c3 <main+0xa3>
mov    -0x28(%rbp),%rax
mov    0x2e26(%rip),%rcx
cmp    (%rcx),%rax
jge    11d5 <main+0xb5>
mov    -0x28(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <main+0x1e>
mov    -0x20(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11b3 <main+0x93>
mov    %rsi,%r14
mov    %edi,%r13d
mov    $0x1,%r15d
mov    0x2ea1(%rip),%r12
xor    %ebx,%ebx
jmp    116a <main+0x4a>
nopl   0x0(%rax,%rax,1)
lea    0xeca(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     11b5 <main+0x95>
mov    (%r14,%r15,8),%rdi
call   1040 <reliable_atol@plt>
mov    %rax,%rbp
lea    0xe83(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    %rbp,%rbx
mov    (%r14,%r15,8),%rsi
lea    0xe81(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    (%r12),%rbp
jg     1150 <main+0x30>
mov    0x2e34(%rip),%rax
cmp    (%rax),%rbp
jge    1161 <main+0x41>
jmp    1150 <main+0x30>
xor    %ebx,%ebx
lea    0xe87(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Running total: %ld + \00"
@.str.1 = [11 x i8] c"%s = %ld \0A\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.2 = [34 x i8] c"Numeric overflow, caused by: %ld\0A\00"
@.str.3 = [17 x i8] c"Grand sum: %ld \0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 0, i64* %6
store i32 1, i32* %5
br label %9
9: ; preds = %44, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %47
13: ; preds = %9
%14 = load i8**, i8*** %4
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @reliable_atol(i8* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = load i64, i64* %6
%23 = load i64, i64* %7
%24 = add i64 %22, %23
store i64 %24, i64* %8
%25 = load i8**, i8*** %4
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = load i64, i64* %8
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %29, i64 %30)
%32 = load i64, i64* %7
%33 = load i64, i64* @INT_MAX
%34 = icmp sgt i64 %32, %33
br i1 %34, label %39, label %35
35: ; preds = %13
%36 = load i64, i64* %7
%37 = load i64, i64* @INT_MIN
%38 = icmp slt i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %35, %13
%40 = load i64, i64* %7
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %39, %35
%43 = load i64, i64* %8
store i64 %43, i64* %6
br label %44
44: ; preds = %42
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %9
47: ; preds = %9
%48 = load i64, i64* %6
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %48)
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Running total: %ld + \00"
@.str.1 = [11 x i8] c"%s = %ld \0A\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.2 = [34 x i8] c"Numeric overflow, caused by: %ld\0A\00"
@.str.3 = [17 x i8] c"Grand sum: %ld \0A\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %23
%7 = phi i64 [ 1, %4 ], [ %24, %23 ]
%8 = phi i64 [ 0, %4 ], [ %13, %23 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i64 @reliable_atol(i8* %10)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i64 %8)
%13 = add i64 %11, %8
%14 = load i8*, i8** %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %14, i64 %13)
%16 = load i64, i64* @INT_MAX
%17 = icmp sgt i64 %11, %16
%18 = load i64, i64* @INT_MIN
%19 = icmp slt i64 %11, %18
%20 = select i1 %17, i1 true, i1 %19
br i1 %20, label %21, label %23
21: ; preds = %6
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %11)
br label %23
23: ; preds = %6, %21
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %6
26: ; preds = %23, %2
%27 = phi i64 [ 0, %2 ], [ %13, %23 ]
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i64 %27)
ret void
}