#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 EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int toupper(char);
int main(int argc, char **argv) {
  char str[] = "Hello, world!";
  for (int i = 0, n = strlen(str); i < n; i++) {
    printf("%c\n", str[i]);
  }
  printf("\n");
  for (int i = 0, n = strlen(str); i < n; i++)
    printf("%c", toupper(str[i]));
  printf("\n\n");
  int sum = 0;
  for (int i = 1; i <= 100; sum += i++)
    ;
  printf("Sum from 0 to 100: %i\n\n", sum);
  int fat = 1;
  for (int i = 1; i <= 5; fat *= i++)
    ;
  printf("factorial(5):%i\n", fat);
  return (EXIT_SUCCESS);
}


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)
mov    0xeb3(%rip),%rax
mov    %rax,-0x1e(%rbp)
mov    0xeb1(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x12(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x1e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    11a9 <main+0x79>
movslq -0x24(%rbp),%rax
movsbl -0x1e(%rbp,%rax,1),%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <main+0x48>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x2c(%rbp)
lea    -0x1e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1202 <main+0xd2>
movslq -0x2c(%rbp),%rax
movsbl -0x1e(%rbp,%rax,1),%edi
call   1030 <toupper@plt>
mov    %eax,%esi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11ca <main+0x9a>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x34(%rbp)
movl   $0x1,-0x38(%rbp)
cmpl   $0x64,-0x38(%rbp)
jg     1243 <main+0x113>
jmp    122d <main+0xfd>
mov    -0x38(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x38(%rbp)
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    121e <main+0xee>
mov    -0x34(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x3c(%rbp)
movl   $0x1,-0x40(%rbp)
cmpl   $0x5,-0x40(%rbp)
jg     1288 <main+0x158>
jmp    1271 <main+0x141>
mov    -0x40(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x40(%rbp)
imul   -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    1262 <main+0x132>
mov    -0x3c(%rbp),%esi
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x6(%rsp)
movabs $0x77202c6f6c6c6548,%rax
2c 20 77
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11a7 <main+0x57>
mov    %eax,%r15d
lea    0xe82(%rip),%r14
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rsp,%rdi
call   1060 <strlen@plt>
test   %eax,%eax
jle    11e9 <main+0x99>
mov    %eax,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%rsp,%rbx,1),%edi
call   1040 <toupper@plt>
mov    %eax,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    11d0 <main+0x80>
lea    0xe38(%rip),%rdi
call   1050 <puts@plt>
lea    0xe16(%rip),%rdi
mov    $0x13ba,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe1b(%rip),%rdi
mov    $0x78,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.str = [14 x i8] c"Hello, world!\00"
@.str = [4 x i8] c"%c\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%c\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
@.str.4 = [24 x i8] c"Sum from 0 to 100: %i\0A\0A\00"
@.str.5 = [17 x i8] c"factorial(5):%i\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [14 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = bitcast [14 x i8]* %6 to i8*
store i32 0, i32* %7
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %8
br label %18
18: ; preds = %29, %2
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %22
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %18
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
%34 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %10
br label %36
36: ; preds = %47, %32
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %50
40: ; preds = %36
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [14 x i8], [14 x i8]* %6, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @toupper(i8 signext %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %40
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %36
50: ; preds = %36
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %11
store i32 1, i32* %12
br label %52
52: ; preds = %56, %50
%53 = load i32, i32* %12
%54 = icmp sle i32 %53, 100
br i1 %54, label %55, label %61
55: ; preds = %52
br label %56
56: ; preds = %55
%57 = load i32, i32* %12
%58 = add nsw i32 %57, 1
store i32 %58, i32* %12
%59 = load i32, i32* %11
%60 = add nsw i32 %59, %57
store i32 %60, i32* %11
br label %52
61: ; preds = %52
%62 = load i32, i32* %11
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %62)
store i32 1, i32* %13
store i32 1, i32* %14
br label %64
64: ; preds = %68, %61
%65 = load i32, i32* %14
%66 = icmp sle i32 %65, 5
br i1 %66, label %67, label %73
67: ; preds = %64
br label %68
68: ; preds = %67
%69 = load i32, i32* %14
%70 = add nsw i32 %69, 1
store i32 %70, i32* %14
%71 = load i32, i32* %13
%72 = mul nsw i32 %71, %69
store i32 %72, i32* %13
br label %64
73: ; preds = %64
%74 = load i32, i32* %13
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 %74)
%76 = load i32, i32* @EXIT_SUCCESS
ret i32 %76
}

LLVM IR (-O2):
@__const.main.str = [14 x i8] c"Hello, world!\00"
@.str = [4 x i8] c"%c\0A\00"
@.str.4 = [24 x i8] c"Sum from 0 to 100: %i\0A\0A\00"
@.str.5 = [17 x i8] c"factorial(5):%i\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [14 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = zext i32 %5 to i64
br label %15
9: ; preds = %15, %2
%10 = call i32 @putchar(i32 10)
%11 = call i32 @strlen(i8* %4)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = zext i32 %11 to i64
br label %28
15: ; preds = %7, %15
%16 = phi i64 [ 0, %7 ], [ %21, %15 ]
%17 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %9, label %15
23: ; preds = %28, %9
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 5050)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i32 120)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
28: ; preds = %13, %28
%29 = phi i64 [ 0, %13 ], [ %34, %28 ]
%30 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @toupper(i8 signext %31)
%33 = call i32 @putchar(i32 %32)
%34 = add nuw nsw i64 %29, 1
%35 = icmp eq i64 %34, %14
br i1 %35, label %23, label %28
}