#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_RDONLY;
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*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ system(char *);
int main() {
  int ret;
  int count;
  int procFile;
  char buff[81];
  bzero(buff, sizeof(buff));
  sprintf(buff, "echo \"hello\" > %s", "/proc/jif");
  printf("%s\n", buff);
  system(buff);
  printf("write success...\n");
  procFile = open("/proc/jif", O_RDONLY);
  if (procFile == -1) {
    perror("Fail to open "
           "/proc/jif");
    exit(-1);
  } else {
    printf("Open success...\n");
  }
  bzero(buff, sizeof(buff));
  ret = read(procFile, buff, 81);
  if (ret == -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    -0x70(%rbp),%rdi
mov    $0x51,%esi
call   1090 <bzero@plt>
lea    -0x70(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    0xe9a(%rip),%rdx
call   10a0 <sprintf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <system@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe5c(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xffffffff,-0x10(%rbp)
jne    1225 <main+0x95>
lea    0xe0e(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    $0x51,%esi
call   1090 <bzero@plt>
mov    -0x10(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x51,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1270 <main+0xe0>
lea    0xde6(%rip),%rdi
call   1080 <perror@plt>
jmp    1282 <main+0xf2>
lea    -0x70(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
call   1050 <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    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x51,%esi
call   10a0 <bzero@plt>
lea    0xe42(%rip),%rsi
lea    0xe71(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
lea    0xe64(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1264 <main+0xc4>
mov    %eax,%ebx
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x51,%esi
call   10a0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x51,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1256 <main+0xb6>
lea    0xe05(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdcc(%rip),%rdi
call   1090 <perror@plt>
jmp    1245 <main+0xa5>
lea    0xda7(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

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

LLVM IR (-O2):
@.str = [18 x i8] c"echo \22hello\22 > %s\00"
@.str.1 = [10 x i8] c"/proc/jif\00"
@O_RDONLY = global i32 0
@.str.4 = [23 x i8] c"Fail to open /proc/jif\00"
@.str.6 = [23 x i8] c"Fail to read /proc/jif\00"
@.str.7 = [11 x i8] c"buff = %s\0A\00"
@str = [17 x i8] c"write success...\00"
@str.8 = [16 x i8] c"Open 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 = call i32 @bzero(i8* %2, i32 81)
%4 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @puts(i8* %2)
%6 = call i32 @system(i8* %2)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0))
%16 = call i32 @bzero(i8* %2, i32 81)
%17 = call i32 @read(i32 %9, i8* %2, i32 81)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
br label %23
21: ; preds = %14
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %2)
br label %23
23: ; preds = %21, %19
%24 = call i32 @close(i32 %9)
ret i32 0
}