#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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main() {
  int ret;
  int procFile;
  char buff[81];
  procFile = open("/proc/proc_test/hello", O_RDWR);
  if (procFile == -1) {
    perror("Fail to open "
           "/proc/proc_test/hello");
    exit(-1);
  } else {
    printf("Open success...\n");
  }
  if ((ret = write(procFile, "hello", strlen("hello"))) == -1) {
    perror("Fail to read "
           "/proc/proc_test/hello");
  } else {
    printf("wriet success\n");
  }
  bzero(buff, sizeof(buff));
  if ((ret = read(procFile, buff, 81)) == -1) {
    perror("Fail to read "
           "/proc/proc_test/hello");
  } else {
    printf("buff = %s\n", buff);
  }
  close(procFile);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe92(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d7 <main+0x47>
lea    0xe38(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    0xe5f(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x64(%rbp),%edi
mov    %eax,%edx
lea    0xe4e(%rip),%rsi
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    1225 <main+0x95>
lea    0xe19(%rip),%rdi
call   1090 <perror@plt>
jmp    1233 <main+0xa3>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x51,%esi
call   10a0 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x51,%edx
call   1070 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    126f <main+0xdf>
lea    0xdcf(%rip),%rdi
call   1090 <perror@plt>
jmp    1281 <main+0xf1>
lea    -0x60(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
lea    0xe79(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xc1>
mov    %eax,%ebx
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    0xe66(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1245 <main+0xa5>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x51,%esi
call   10b0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x51,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     1253 <main+0xb3>
lea    0xe1c(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
jmp    11ff <main+0x5f>
lea    0xdc9(%rip),%rdi
call   10a0 <perror@plt>
jmp    1234 <main+0x94>
lea    0xd98(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"/proc/proc_test/hello\00"
@O_RDWR = global i32 0
@.str.1 = [35 x i8] c"Fail to open /proc/proc_test/hello\00"
@.str.2 = [17 x i8] c"Open success...\0A\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [35 x i8] c"Fail to read /proc/proc_test/hello\00"
@.str.5 = [15 x i8] c"wriet success\0A\00"
@.str.6 = [11 x i8] c"buff = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [81 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @exit(i32 -1)
unreachable
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12
%15 = load i32, i32* %3
%16 = call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @write(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %16)
store i32 %17, i32* %2
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%25 = call i32 @bzero(i8* %24, i32 81)
%26 = load i32, i32* %3
%27 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 81)
store i32 %28, i32* %2
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %35
32: ; preds = %23
%33 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %33)
br label %35
35: ; preds = %32, %30
%36 = load i32, i32* %3
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
@.str = [22 x i8] c"/proc/proc_test/hello\00"
@O_RDWR = global i32 0
@.str.1 = [35 x i8] c"Fail to open /proc/proc_test/hello\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [35 x i8] c"Fail to read /proc/proc_test/hello\00"
@.str.6 = [11 x i8] c"buff = %s\0A\00"
@str = [16 x i8] c"Open success...\00"
@str.7 = [14 x i8] c"wriet success\00"
define i32 @main() {
%1 = alloca [81 x i8]
%2 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @write(i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %18
16: ; preds = %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %18
18: ; preds = %16, %14
%19 = call i32 @bzero(i8* %2, i32 81)
%20 = call i32 @read(i32 %4, i8* %2, i32 81)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %26
24: ; preds = %18
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %2)
br label %26
26: ; preds = %24, %22
%27 = call i32 @close(i32 %4)
ret i32 0
}