#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] = "hello";
  procFile = open("/proc/jif", O_RDWR);
  if (procFile == -1) {
    perror("Fail to open "
           "/proc/jif");
    exit(-1);
  } else {
    printf("Open success...\n");
  }
  printf("user buffer : %p\n", buff);
  if ((ret = write(procFile, buff, strlen(buff))) == -1) {
    perror("Fail to read "
           "/proc/jif");
  } else {
    printf("wriet success\n");
  }
  bzero(buff, sizeof(buff));
  if ((ret = read(procFile, buff, 81)) == -1) {
    perror("Fail to read "
           "/proc/jif");
  } 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)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x51,%edx
call   1060 <memset@plt>
movb   $0x68,-0x60(%rbp)
movb   $0x65,-0x5f(%rbp)
movb   $0x6c,-0x5e(%rbp)
movb   $0x6c,-0x5d(%rbp)
movb   $0x6f,-0x5c(%rbp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
lea    0xe64(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    120b <main+0x6b>
lea    0xe04(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x6c(%rbp)
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    126d <main+0xcd>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
jmp    127b <main+0xdb>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x51,%esi
call   10b0 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x51,%edx
call   1080 <read@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
jne    12b7 <main+0x117>
lea    0xd8d(%rip),%rdi
call   10a0 <perror@plt>
jmp    12c9 <main+0x129>
lea    -0x60(%rbp),%rsi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
movl   $0x6c6c6568,(%rsp)
movb   $0x6f,0x4(%rsp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1298 <main+0xf8>
mov    %eax,%ebp
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
lea    0xe12(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     127c <main+0xdc>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x51,%esi
call   10b0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x51,%edx
call   1080 <read@plt>
cmp    $0xffffffff,%eax
je     128a <main+0xea>
lea    0xdde(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xda6(%rip),%rdi
call   10a0 <perror@plt>
jmp    1237 <main+0x97>
lea    0xd98(%rip),%rdi
call   10a0 <perror@plt>
jmp    126c <main+0xcc>
lea    0xd61(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/proc/jif\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Fail to open /proc/jif\00"
@.str.2 = [17 x i8] c"Open success...\0A\00"
@.str.3 = [18 x i8] c"user buffer : %p\0A\00"
@.str.4 = [23 x i8] c"Fail to read /proc/jif\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 = bitcast [81 x i8]* %4 to i8*
%6 = bitcast i8* %5 to [81 x i8]*
%7 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i32 0, i32 0
store i8 104, i8* %7
%8 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i32 0, i32 1
store i8 101, i8* %8
%9 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i32 0, i32 2
store i8 108, i8* %9
%10 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i32 0, i32 3
store i8 108, i8* %10
%11 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i32 0, i32 4
store i8 111, i8* %11
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19
%22 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %3
%25 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%26 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @write(i32 %24, i8* %25, i32 %27)
store i32 %28, i32* %2
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %34
32: ; preds = %21
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %34
34: ; preds = %32, %30
%35 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%36 = call i32 @bzero(i8* %35, i32 81)
%37 = load i32, i32* %3
%38 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 81)
store i32 %39, i32* %2
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %46
43: ; preds = %34
%44 = getelementptr inbounds [81 x i8], [81 x i8]* %4, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %43, %41
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@.str = [10 x i8] c"/proc/jif\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Fail to open /proc/jif\00"
@.str.3 = [18 x i8] c"user buffer : %p\0A\00"
@.str.4 = [23 x i8] c"Fail to read /proc/jif\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
store i8 104, i8* %2
%3 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 1
store i8 101, i8* %3
%4 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 2
store i8 108, i8* %4
%5 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 3
store i8 108, i8* %5
%6 = getelementptr inbounds [81 x i8], [81 x i8]* %1, i64 0, i64 4
store i8 111, i8* %6
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%16 = call i32 @strlen(i8* %2)
%17 = call i32 @write(i32 %8, i8* %2, i32 %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %23
21: ; preds = %13
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.7, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = call i32 @bzero(i8* %2, i32 81)
%25 = call i32 @read(i32 %8, i8* %2, i32 81)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = 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 %31
31: ; preds = %29, %27
%32 = call i32 @close(i32 %8)
ret i32 0
}