#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 O_CREAT;
int O_RDWR;
int S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ close(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, fd_1;
  char *buff = "test write";
  char buff_1[1024];
  fd = open("test.txt", 04000000 | O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
  write(fd, buff, 10);
  fd_1 = open("test.txt", 04000000 | O_RDWR | O_CREAT, S_IREAD | S_IWRITE);
  read(fd_1, buff_1, 1024);
  printf("Il contenuto del file è:%s\n", buff_1);
  close(fd_1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
or     $0x100000,%esi
mov    0x2e6e(%rip),%rax
or     (%rax),%esi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    0x2e3c(%rip),%rax
or     (%rax),%edx
lea    0xe66(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <write@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
or     $0x100000,%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
mov    0x2df2(%rip),%rax
or     (%rax),%edx
lea    0xe1c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x420(%rbp),%rsi
lea    0xdfb(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2e78(%rip),%r13
mov    0x0(%r13),%esi
mov    0x2e85(%rip),%r15
or     (%r15),%esi
or     $0x100000,%esi
mov    0x2e45(%rip),%r12
mov    0x2e4e(%rip),%rbp
mov    0x0(%rbp),%edx
or     (%r12),%edx
lea    0xe73(%rip),%r14
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0xe57(%rip),%rsi
mov    %eax,%edi
mov    $0xa,%edx
call   1030 <write@plt>
mov    0x0(%r13),%esi
or     (%r15),%esi
or     $0x100000,%esi
mov    0x0(%rbp),%edx
or     (%r12),%edx
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xe28(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"test write\00"
@.str.1 = [9 x i8] c"test.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.2 = [29 x i8] c"Il contenuto del file \C3\A8:%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %8
%10 = load i32, i32* @O_RDWR
%11 = or i32 1048576, %10
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IREAD
%15 = load i32, i32* @S_IWRITE
%16 = or i32 %14, %15
%17 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %16)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = load i8*, i8** %8
%20 = call i32 @write(i32 %18, i8* %19, i32 10)
%21 = load i32, i32* @O_RDWR
%22 = or i32 1048576, %21
%23 = load i32, i32* @O_CREAT
%24 = or i32 %22, %23
%25 = load i32, i32* @S_IREAD
%26 = load i32, i32* @S_IWRITE
%27 = or i32 %25, %26
%28 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %27)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 1024)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %7
%35 = call i32 @close(i32 %34)
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"test write\00"
@.str.1 = [9 x i8] c"test.txt\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@.str.2 = [29 x i8] c"Il contenuto del file \C3\A8:%s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_RDWR
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = or i32 %7, 1048576
%9 = load i32, i32* @S_IREAD
%10 = load i32, i32* @S_IWRITE
%11 = or i32 %10, %9
%12 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %11)
%13 = tail call i32 @write(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 10)
%14 = load i32, i32* @O_RDWR
%15 = load i32, i32* @O_CREAT
%16 = or i32 %14, %15
%17 = or i32 %16, 1048576
%18 = load i32, i32* @S_IREAD
%19 = load i32, i32* @S_IWRITE
%20 = or i32 %19, %18
%21 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %20)
%22 = call i32 @read(i32 %21, i8* %4, i32 1024)
%23 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%24 = call i32 @close(i32 %21)
%25 = call i32 @close(i32 %12)
ret i32 0
}