#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*/ close(int);
int /*<<< orphan*/ creat(char *, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int i, j, k;
  char buf[1025];
  creat("new.c", 0777);
  k = open("new.c", 1);
  write(k, "printf hello world", 50);
  close(3);
  j = open("new.c", 0);
  i = read(j, buf, 100);
  buf[i] = '\0';
  printf("%s", buf);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x1ff,%esi
call   1080 <creat@plt>
lea    0xe76(%rip),%rdi
mov    $0x1,%esi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
lea    0xe65(%rip),%rsi
mov    $0x32,%edx
call   1030 <write@plt>
mov    $0x3,%edi
call   1050 <close@plt>
lea    0xe44(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1090 <creat@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1080 <open@plt>
lea    0xe66(%rip),%rsi
mov    %eax,%edi
mov    $0x32,%edx
call   1040 <write@plt>
mov    $0x3,%edi
call   1060 <close@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <open@plt>
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe3a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"new.c\00"
@.str.1 = [19 x i8] c"printf hello world\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1025 x i8]
store i32 0, i32* %1
%6 = call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 511)
%7 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = call i32 @write(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 50)
%10 = call i32 @close(i32 3)
%11 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 100)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [1025 x i8], [1025 x i8]* %5, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"new.c\00"
@.str.1 = [19 x i8] c"printf hello world\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca [1025 x i8]
%2 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @creat(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 511)
%4 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 50)
%6 = tail call i32 @close(i32 3)
%7 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%8 = call i32 @read(i32 %7, i8* %2, i32 100)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%12 = call i32 @putchar(i32 10)
ret i32 0
}