#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);
int main(int argc, char *argv[]) {
  int i, j;
  int sum = 0;
  const char *str = argv[1];
  register const char *s, *t;
  for (t = str; *t; ++t) {
    sum += *t;
  }
  printf("Sum is: %d\n", sum);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     116c <main+0x5c>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1141 <main+0x31>
mov    -0x1c(%rbp),%esi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    0x8(%rsi),%rax
mov    (%rax),%cl
test   %cl,%cl
je     1142 <main+0x32>
add    $0x1,%rax
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %cl,%ecx
add    %ecx,%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1130 <main+0x20>
jmp    1144 <main+0x34>
xor    %esi,%esi
lea    0xeb5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Sum is: %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 i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
store i8* %14, i8** %9
%15 = load i8*, i8** %9
store i8* %15, i8** %11
br label %16
16: ; preds = %26, %2
%17 = load i8*, i8** %11
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8*, i8** %11
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i32, i32* %8
%25 = add nsw i32 %24, %23
store i32 %25, i32* %8
br label %26
26: ; preds = %20
%27 = load i8*, i8** %11
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %11
br label %16
29: ; preds = %16
%30 = load i32, i32* %8
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %30)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"Sum is: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %2, %7
%8 = phi i8 [ %14, %7 ], [ %5, %2 ]
%9 = phi i8* [ %13, %7 ], [ %4, %2 ]
%10 = phi i32 [ %12, %7 ], [ 0, %2 ]
%11 = sext i8 %8 to i32
%12 = add nsw i32 %10, %11
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %7
16: ; preds = %7, %2
%17 = phi i32 [ 0, %2 ], [ %12, %7 ]
%18 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %17)
ret i32 0
}