#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 */
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int do_work(int argc, char *argv[], const char *name) {
  int index;
  char *endptr;
  char *start;
  unsigned long sum = 0L;
  unsigned long num;
  for (index = 1; index < argc; index++) {
    start = argv[index];
    if (*start == (char)0) {
      fprintf(stderr, "%s: argument %d is empty.\n", name, index);
      return 1;
    }
    errno = 0;
    num = strtoul(start, &endptr, 0);
    if (errno != 0) {
      fprintf(stderr, "%s: can't convert '%s'. Errno=%d (%s)\n", name, start,
              errno, strerror(errno));
      return 1;
    }
    if (*endptr != (char)0) {
      fprintf(stderr, "%s: there is illegal symbols in '%s'.\n", name, start);
      return 1;
    }
    sum += num;
  }
  printf("0x%lx\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<do_work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12a4 <do_work+0x164>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11b8 <do_work+0x78>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <do_work+0x17b>
mov    0x2e19(%rip),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x40(%rbp)
mov    0x2df8(%rip),%rax
cmpq   $0x0,(%rax)
je     124f <do_work+0x10f>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    %rax,%r9
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <do_work+0x17b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     128a <do_work+0x14a>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bb <do_work+0x17b>
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1162 <do_work+0x22>
mov    -0x38(%rbp),%rsi
lea    0xdba(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_work>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     11b6 <do_work+0x76>
mov    %rsi,%r12
mov    %rdx,(%rsp)
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x1,%ebx
xor    %r13d,%r13d
mov    0x2e68(%rip),%r14
mov    (%r12,%rbx,8),%rbp
cmpb   $0x0,0x0(%rbp)
je     11d9 <do_work+0x99>
movq   $0x0,(%r14)
mov    %rbp,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    (%r14),%r15
test   %r15,%r15
jne    11fd <do_work+0xbd>
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    1232 <do_work+0xf2>
add    %rax,%r13
add    $0x1,%rbx
cmp    %rbx,0x8(%rsp)
jne    1170 <do_work+0x30>
jmp    11b9 <do_work+0x79>
xor    %r13d,%r13d
lea    0xea9(%rip),%rdi
mov    %r13,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe17(%rip),%rsi
mov    (%rsp),%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11ca <do_work+0x8a>
mov    0x2ddc(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rdi
call   1060 <strerror@plt>
lea    0xe06(%rip),%rsi
mov    %ebx,%edi
mov    (%rsp),%rdx
mov    %rbp,%rcx
mov    %r15,%r8
mov    %rax,%r9
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11ca <do_work+0x8a>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
mov    (%rsp),%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    11ca <do_work+0x8a>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"%s: argument %d is empty.\0A\00"
@errno = global i64 0
@.str.1 = [39 x i8] c"%s: can't convert '%s'. Errno=%d (%s)\0A\00"
@.str.2 = [39 x i8] c"%s: there is illegal symbols in '%s'.\0A\00"
@.str.3 = [7 x i8] c"0x%lx\0A\00"
define i32 @do_work(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i64 0, i64* %11
store i32 1, i32* %8
br label %13
13: ; preds = %59, %3
%14 = load i32, i32* %8
%15 = load i32, i32* %5
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %62
17: ; preds = %13
%18 = load i8**, i8*** %6
%19 = load i32, i32* %8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8*, i8** %18, i64 %20
%22 = load i8*, i8** %21
store i8* %22, i8** %10
%23 = load i8*, i8** %10
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %7
%30 = load i32, i32* %8
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30)
store i32 1, i32* %4
br label %65
32: ; preds = %17
store i64 0, i64* @errno
%33 = load i8*, i8** %10
%34 = call i64 @strtoul(i8* %33, i8** %9, i32 0)
store i64 %34, i64* %12
%35 = load i64, i64* @errno
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %7
%40 = load i8*, i8** %10
%41 = load i64, i64* @errno
%42 = load i64, i64* @errno
%43 = call i8* @strerror(i64 %42)
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %40, i64 %41, i8* %43)
store i32 1, i32* %4
br label %65
45: ; preds = %32
%46 = load i8*, i8** %9
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %55
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i8*, i8** %7
%53 = load i8*, i8** %10
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %52, i8* %53)
store i32 1, i32* %4
br label %65
55: ; preds = %45
%56 = load i64, i64* %12
%57 = load i64, i64* %11
%58 = add i64 %57, %56
store i64 %58, i64* %11
br label %59
59: ; preds = %55
%60 = load i32, i32* %8
%61 = add nsw i32 %60, 1
store i32 %61, i32* %8
br label %13
62: ; preds = %13
%63 = load i64, i64* %11
%64 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %63)
store i32 0, i32* %4
br label %65
65: ; preds = %62, %50, %37, %27
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"%s: argument %d is empty.\0A\00"
@errno = global i64 0
@.str.1 = [39 x i8] c"%s: can't convert '%s'. Errno=%d (%s)\0A\00"
@.str.2 = [39 x i8] c"%s: there is illegal symbols in '%s'.\0A\00"
@.str.3 = [7 x i8] c"0x%lx\0A\00"
define i32 @do_work(i32 %0, i8** nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %39
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %35
%10 = phi i64 [ 1, %7 ], [ %37, %35 ]
%11 = phi i64 [ 0, %7 ], [ %36, %35 ]
%12 = getelementptr inbounds i8*, i8** %1, i64 %10
%13 = load i8*, i8** %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = trunc i64 %10 to i32
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %17)
br label %42
20: ; preds = %9
store i64 0, i64* @errno
%21 = call i64 @strtoul(i8* %13, i8** %4, i32 0)
%22 = load i64, i64* @errno
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = tail call i8* @strerror(i64 %22)
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %13, i64 %22, i8* %26)
br label %42
28: ; preds = %20
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %2, i8* %13)
br label %42
35: ; preds = %28
%36 = add i64 %21, %11
%37 = add nuw nsw i64 %10, 1
%38 = icmp eq i64 %37, %8
br i1 %38, label %39, label %9
39: ; preds = %35, %3
%40 = phi i64 [ 0, %3 ], [ %36, %35 ]
%41 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i64 %40)
br label %42
42: ; preds = %39, %32, %24, %16
%43 = phi i32 [ 1, %16 ], [ 1, %24 ], [ 1, %32 ], [ 0, %39 ]
ret i32 %43
}