#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*/ cheng2(char *);
int /*<<< orphan*/ printf(char *, int);
int sum(char *);
int main() {
  char a[1000];
  int i;
  for (i = 0; i < 1000; i++)
    a[i] = 10;
  a[0] = 1;
  for (i = 0; i < 1000; i++) {
    cheng2(a);
  }
  printf("%d\n", sum(a));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x3f4(%rbp)
cmpl   $0x3e8,-0x3f4(%rbp)
jge    117f <main+0x4f>
movslq -0x3f4(%rbp),%rax
movb   $0xa,-0x3f0(%rbp,%rax,1)
0a
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    114c <main+0x1c>
movb   $0x1,-0x3f0(%rbp)
movl   $0x0,-0x3f4(%rbp)
cmpl   $0x3e8,-0x3f4(%rbp)
jge    11c0 <main+0x90>
lea    -0x3f0(%rbp),%rdi
call   1040 <cheng2@plt>
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
jmp    1190 <main+0x60>
lea    -0x3f0(%rbp),%rdi
call   1050 <sum@plt>
mov    %eax,%esi
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
mov    %rsp,%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <memset@plt>
movb   $0x1,(%rsp)
mov    $0x3e8,%ebp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <cheng2@plt>
add    $0xffffffff,%ebp
jne    1170 <main+0x30>
mov    %rsp,%rdi
call   1060 <sum@plt>
lea    0xe74(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %11, %0
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 1000
br i1 %6, label %7, label %14
7: ; preds = %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %9
store i8 10, i8* %10
br label %11
11: ; preds = %7
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %4
14: ; preds = %4
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
store i8 1, i8* %15
store i32 0, i32* %3
br label %16
16: ; preds = %22, %14
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 1000
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%21 = call i32 @cheng2(i8* %20)
br label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %16
25: ; preds = %16
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%27 = call i32 @sum(i8* %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
store i8 1, i8* %3
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %7, %4 ]
%6 = call i32 @cheng2(i8* %3)
%7 = add nuw nsw i32 %5, 1
%8 = icmp eq i32 %7, 1000
br i1 %8, label %9, label %4
9: ; preds = %4
%10 = call i32 @sum(i8* %3)
%11 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %10)
ret i32 0
}