#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ lseek(int, long, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int);
main() {
  int fd;
  char *s;
  char *filePath = "/tmp/test/test.txt";
  fd = creat(filePath, 0777);
  if (fd == -1) {
    write(1, "can't create file!\n", 19);
  }
  fd = open(filePath, O_RDWR, 0);
  write(fd, "This is test!", 13);
  lseek(fd, 0L, 0);
  read(fd, s, 10);
  write(1, s, 10);
  write(1, "\n", 1);
  write(1, "test", 4);
  write(1, "\n", 1);
  close(fd);
  unlink(filePath);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x1ff,%esi
call   1090 <creat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11bb <main+0x4b>
mov    $0x1,%edi
lea    0xe62(%rip),%rsi
mov    $0x13,%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe4b(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%rsi
mov    $0x1,%edi
mov    $0xa,%edx
call   1040 <write@plt>
mov    $0x1,%edx
lea    0xe01(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
mov    $0x1,%edi
lea    0xdfe(%rip),%rsi
mov    $0x4,%edx
call   1040 <write@plt>
mov    $0x1,%edx
lea    0xdd8(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xe85(%rip),%rdi
mov    $0x1ff,%esi
call   1090 <creat@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x30>
lea    0xe82(%rip),%rsi
mov    $0x1,%edi
mov    $0x13,%edx
call   1040 <write@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,%ebp
lea    0xe64(%rip),%rsi
mov    %eax,%edi
mov    $0xd,%edx
call   1040 <write@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <lseek@plt>
mov    %ebp,%edi
mov    $0xa,%edx
call   1070 <read@plt>
mov    $0x1,%edi
mov    $0xa,%edx
call   1040 <write@plt>
lea    0xe29(%rip),%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xe20(%rip),%rsi
mov    $0x1,%edi
mov    $0x4,%edx
call   1040 <write@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/test/test.txt\00"
@.str.1 = [20 x i8] c"can't create file!\0A\00"
@O_RDWR = global i32 0
@.str.2 = [14 x i8] c"This is test!\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"test\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %4
%6 = call i32 @creat(i8* %5, i32 511)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 19)
br label %11
11: ; preds = %9, %0
%12 = load i8*, i8** %4
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13, i32 0)
store i32 %14, i32* %2
%15 = load i32, i32* %2
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%17 = load i32, i32* %2
%18 = call i32 @lseek(i32 %17, i64 0, i32 0)
%19 = load i32, i32* %2
%20 = load i8*, i8** %3
%21 = call i32 @read(i32 %19, i8* %20, i32 10)
%22 = load i8*, i8** %3
%23 = call i32 @write(i32 1, i8* %22, i32 10)
%24 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%25 = call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%26 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%27 = load i32, i32* %2
%28 = call i32 @close(i32 %27)
%29 = load i8*, i8** %4
%30 = call i32 @unlink(i8* %29)
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/test/test.txt\00"
@.str.1 = [20 x i8] c"can't create file!\0A\00"
@O_RDWR = global i32 0
@.str.2 = [14 x i8] c"This is test!\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [5 x i8] c"test\00"
define i32 @main() {
%1 = tail call i32 @creat(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 511)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %5
3: ; preds = %0
%4 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 19)
br label %5
5: ; preds = %3, %0
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6, i32 0)
%8 = tail call i32 @write(i32 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%9 = tail call i32 @lseek(i32 %7, i64 0, i32 0)
%10 = tail call i32 @read(i32 %7, i8* undef, i32 10)
%11 = tail call i32 @write(i32 1, i8* undef, i32 10)
%12 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%13 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4)
%14 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1)
%15 = tail call i32 @close(i32 %7)
%16 = tail call i32 @unlink(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
ret i32 0
}