#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 */
typedef int /*<<< orphan*/ buf_2;
typedef int /*<<< orphan*/ buf_1;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int write(int, char *, int);
int main(void) {
  int fd;
  char buf_1[] = "hello world\n";
  char buf_2[50];
  if ((fd = open("hello_test.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1)
    printf("can't open or create hello_test.txt\n");
  if (write(fd, buf_1, sizeof(buf_1)) == -1)
    printf("can't write to hello_test.txt\n");
  if (close(fd) == -1)
    printf("can't close\n");
  if ((fd = open("hello_test.txt", O_RDONLY)) == -1)
    printf("can't open hello_test.txt\n");
  if (read(fd, buf_2, sizeof(buf_2)) == -1)
    printf("can't read hello_test.txt\n");
  else
    printf("%s", buf_2);
  if (close(fd) == -1)
    printf("can't close\n");
  if ((fd = open("hello_test.txt", O_RDONLY)) == -1)
    printf("can't open hello_test.txt\n");
  if (lseek(fd, 6, SEEK_SET) == -1)
    printf("can't lseek\n");
  if (read(fd, buf_2, sizeof(buf_2)) == -1)
    printf("can't read hello_test.txt\n");
  else
    printf("%s", buf_2);
  if (close(fd) == -1)
    printf("can't close\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x15(%rbp)
mov    0xe78(%rip),%eax
mov    %eax,-0xd(%rbp)
mov    0xe73(%rip),%al
mov    %al,-0x9(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    0x2e4c(%rip),%rax
or     (%rax),%esi
mov    0x2e3b(%rip),%rax
or     (%rax),%esi
lea    0xe4f(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    11e4 <main+0x74>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    120c <main+0x9c>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    122b <main+0xbb>
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    125c <main+0xec>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1289 <main+0x119>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    129b <main+0x12b>
lea    -0x50(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    12ba <main+0x14a>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d17(%rip),%rax
mov    (%rax),%esi
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12eb <main+0x17b>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1318 <main+0x1a8>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
jne    1345 <main+0x1d5>
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1357 <main+0x1e7>
lea    -0x50(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1376 <main+0x206>
lea    0xcf1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
movabs $0xa646c726f7720,%rax
mov    %rax,0x5(%rsp)
mov    0x2e1b(%rip),%rax
mov    0x2e54(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,(%rsp)
mov    0x2e33(%rip),%rax
or     (%rax),%esi
lea    0xe61(%rip),%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11e5 <main+0x65>
lea    0xe9a(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xd,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1205 <main+0x85>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    121d <main+0x9d>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    0x2db4(%rip),%r14
mov    (%r14),%esi
lea    0xdf9(%rip),%rdi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1248 <main+0xc8>
lea    0xdf3(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x32,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
jne    126c <main+0xec>
lea    0xdb7(%rip),%rdi
call   1030 <puts@plt>
jmp    127f <main+0xff>
lea    0xd9a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1297 <main+0x117>
lea    0xdbe(%rip),%rdi
call   1030 <puts@plt>
mov    (%r14),%esi
lea    0xd86(%rip),%rdi
xor    %eax,%eax
call   1090 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    12bb <main+0x13b>
lea    0xd80(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x6,%esi
call   1060 <lseek@plt>
cmp    $0xffffffff,%eax
jne    12e1 <main+0x161>
lea    0xd34(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x32,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
jne    1305 <main+0x185>
lea    0xd1e(%rip),%rdi
call   1030 <puts@plt>
jmp    1318 <main+0x198>
lea    0xd01(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1330 <main+0x1b0>
lea    0xd25(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.buf_1 = [13 x i8] c"hello world\0A\00"
@.str = [15 x i8] c"hello_test.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.1 = [37 x i8] c"can't open or create hello_test.txt\0A\00"
@.str.2 = [31 x i8] c"can't write to hello_test.txt\0A\00"
@.str.3 = [13 x i8] c"can't close\0A\00"
@O_RDONLY = global i32 0
@.str.4 = [27 x i8] c"can't open hello_test.txt\0A\00"
@.str.5 = [27 x i8] c"can't read hello_test.txt\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@SEEK_SET = global i32 0
@.str.7 = [13 x i8] c"can't lseek\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [13 x i8]
%4 = alloca [50 x i8]
store i32 0, i32* %1
%5 = bitcast [13 x i8]* %3 to i8*
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %6, %7
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %10, i32 438)
store i32 %11, i32* %2
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = load i32, i32* %2
%17 = getelementptr inbounds [13 x i8], [13 x i8]* %3, i64 0, i64 0
%18 = call i32 @write(i32 %16, i8* %17, i32 13)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %15
%23 = load i32, i32* %2
%24 = call i32 @close(i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = load i32, i32* @O_RDONLY
%30 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %29)
store i32 %30, i32* %2
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = load i32, i32* %2
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%37 = call i32 @read(i32 %35, i8* %36, i32 50)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %44
41: ; preds = %34
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %41, %39
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %50
50: ; preds = %48, %44
%51 = load i32, i32* @O_RDONLY
%52 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %51)
store i32 %52, i32* %2
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
%57 = load i32, i32* %2
%58 = load i32, i32* @SEEK_SET
%59 = call i32 @lseek(i32 %57, i32 6, i32 %58)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %61, %56
%64 = load i32, i32* %2
%65 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%66 = call i32 @read(i32 %64, i8* %65, i32 50)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %63
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %73
70: ; preds = %63
%71 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %71)
br label %73
73: ; preds = %70, %68
%74 = load i32, i32* %2
%75 = call i32 @close(i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %79
77: ; preds = %73
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %79
79: ; preds = %77, %73
%80 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@__const.main.buf_1 = [13 x i8] c"hello world\0A\00"
@.str = [15 x i8] c"hello_test.txt\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_RDONLY = global i32 0
@.str.6 = [3 x i8] c"%s\00"
@SEEK_SET = global i32 0
@str.9 = [12 x i8] c"can't lseek\00"
@str.12 = [26 x i8] c"can't read hello_test.txt\00"
@str.13 = [26 x i8] c"can't open hello_test.txt\00"
@str.14 = [12 x i8] c"can't close\00"
@str.15 = [30 x i8] c"can't write to hello_test.txt\00"
@str.16 = [36 x i8] c"can't open or create hello_test.txt\00"
define i32 @main() {
%1 = alloca [13 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [13 x i8], [13 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = load i32, i32* @O_TRUNC
%9 = or i32 %7, %8
%10 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %9, i32 438)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.16, i64 0, i64 0))
br label %14
14: ; preds = %12, %0
%15 = call i32 @write(i32 %10, i8* %3, i32 13)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.15, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
%20 = tail call i32 @close(i32 %10)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i32, i32* @O_RDONLY
%26 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = call i32 @read(i32 %26, i8* %4, i32 50)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
br label %37
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %37
37: ; preds = %35, %33
%38 = call i32 @close(i32 %26)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* @O_RDONLY
%44 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.13, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* @SEEK_SET
%50 = call i32 @lseek(i32 %44, i32 6, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %54
54: ; preds = %52, %48
%55 = call i32 @read(i32 %44, i8* %4, i32 50)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.12, i64 0, i64 0))
br label %61
59: ; preds = %54
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %61
61: ; preds = %59, %57
%62 = call i32 @close(i32 %44)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.14, i64 0, i64 0))
br label %66
66: ; preds = %64, %61
%67 = call i32 @exit(i32 0)
unreachable
}