#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() {
  char src[] = "hello world!\0";
  char dest[256];
  int i = 0;
  for (i = 0; src[i] != '\0'; ++i)
    dest[i] = src[i];
  printf("%i\n", i);
  dest[i] = '\0';
  printf("%s\n", dest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xed7(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xed5(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xecf(%rip),%ax
mov    %ax,-0x6(%rbp)
movl   $0x0,-0x124(%rbp)
movl   $0x0,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1197 <main+0x87>
movslq -0x124(%rbp),%rax
mov    -0x12(%rbp,%rax,1),%cl
movslq -0x124(%rbp),%rax
mov    %cl,-0x120(%rbp,%rax,1)
mov    -0x124(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x124(%rbp)
jmp    1155 <main+0x45>
mov    -0x124(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rsi
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x108,%rsp
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,(%rsp)
movl   $0x21646c72,0x8(%rsp)
21
lea    0xeca(%rip),%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movb   $0x0,0xc(%rsp)
mov    %rsp,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x108,%rsp
ret

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

LLVM IR (-O2):
@__const.main.src = [14 x i8] c"hello world!\00\00"
@.str = [4 x i8] c"%i\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 12)
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 12
store i8 0, i8* %5
%6 = call i32 @puts(i8* %3)
ret i32 0
}