#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 damm_checksum(int);
int /*<<< orphan*/ printf(char *, int, int);
int strlen(char *);
int strtol(char *, char **, int);
int main(int argc, char *argv[]) {
  int i, n;
  char *end;
  for (i = 1; i < argc; i++) {
    n = strtol(argv[i], &end, 10);
    if ((end - argv[i]) < strlen(argv[i]))
      continue;
    printf("n: %d, checksum: %d\n", n, damm_checksum(n));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f2 <main+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    11c5 <main+0x85>
jmp    11e4 <main+0xa4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%edi
call   1060 <damm_checksum@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115d <main+0x1d>
xor    %eax,%eax
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     11ae <main+0x6e>
mov    %rsi,%r13
mov    %edi,%r12d
mov    $0x1,%ebx
mov    %rsp,%r14
jmp    1169 <main+0x29>
add    $0x1,%rbx
cmp    %rbx,%r12
je     11ae <main+0x6e>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ebp
mov    (%rsp),%r15
mov    0x0(%r13,%rbx,8),%rdi
sub    %rdi,%r15
call   1030 <strlen@plt>
cltq
cmp    %rax,%r15
jl     1160 <main+0x20>
mov    %ebp,%edi
call   1060 <damm_checksum@plt>
lea    0xe5d(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1040 <printf@plt>
jmp    1160 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"n: %d, checksum: %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 i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %9
9: ; preds = %43, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %46
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @strtol(i8* %18, i8** %8, i32 10)
store i32 %19, i32* %7
%20 = load i8*, i8** %8
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = ptrtoint i8* %20 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = load i8**, i8*** %5
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %28, %35
br i1 %36, label %37, label %38
37: ; preds = %13
br label %43
38: ; preds = %13
%39 = load i32, i32* %7
%40 = load i32, i32* %7
%41 = call i32 @damm_checksum(i32 %40)
%42 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %39, i32 %41)
br label %43
43: ; preds = %38, %37
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %9
46: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"n: %d, checksum: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %27
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %24
%9 = phi i64 [ 1, %6 ], [ %25, %24 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @strtol(i8* %11, i8** %3, i32 10)
%13 = load i8*, i8** %3
%14 = load i8*, i8** %10
%15 = ptrtoint i8* %13 to i64
%16 = ptrtoint i8* %14 to i64
%17 = sub i64 %15, %16
%18 = tail call i32 @strlen(i8* %14)
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %17, %19
br i1 %20, label %24, label %21
21: ; preds = %8
%22 = tail call i32 @damm_checksum(i32 %12)
%23 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %22)
br label %24
24: ; preds = %8, %21
%25 = add nuw nsw i64 %9, 1
%26 = icmp eq i64 %25, %7
br i1 %26, label %27, label %8
27: ; preds = %24, %2
ret i32 0
}