#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 main(int argc, char *argv[]) {
  int i;
  int sum = 0;
  if (argc < 2) {
    printf("Usage: program-name char\n");
    return 1;
  }
  for (i = 0; i < argv[1][0]; i++)
    sum += i;
  printf("Sum is: %d\n", sum);
  return 0;
}


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,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1151 <main+0x41>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    119d <main+0x8d>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jge    1185 <main+0x75>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <main+0x48>
mov    -0x18(%rbp),%esi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jge    1139 <main+0x19>
lea    0xedf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    116c <main+0x4c>
mov    0x8(%rsi),%rax
movsbl (%rax),%eax
xor    %ebx,%ebx
mov    $0x0,%esi
test   %eax,%eax
jle    115e <main+0x3e>
lea    -0x1(%rax),%ecx
lea    -0x2(%rax),%edx
imul   %rcx,%rdx
shr    %rdx
lea    (%rax,%rdx,1),%esi
add    $0xffffffff,%esi
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str.1 = [12 x i8] c"Sum is: %d\0A\00"
@str = [25 x i8] c"Usage: program-name char\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp sgt i8 %7, 0
br i1 %9, label %10, label %22
10: ; preds = %4
%11 = add nsw i32 %8, -1
%12 = zext i32 %11 to i33
%13 = add nsw i32 %8, -2
%14 = zext i32 %13 to i33
%15 = mul i33 %12, %14
%16 = lshr i33 %15, 1
%17 = trunc i33 %16 to i32
%18 = add i32 %8, %17
%19 = add i32 %18, -1
br label %22
20: ; preds = %2
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %25
22: ; preds = %10, %4
%23 = phi i32 [ 0, %4 ], [ %19, %10 ]
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ 1, %20 ], [ 0, %22 ]
ret i32 %26
}