#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 O_RDONLY;
int O_RSYNC;
int /*<<< orphan*/ close(int);
int open(char *, int);
int read(int, char *, int);
int read_proc(char *buf) {
  int triggerFd;
  int res;
  triggerFd = open("/proc/ivhs/feedback", O_RDONLY | O_RSYNC);
  if (triggerFd == -1)
    return -1;
  res = read(triggerFd, buf, 8);
  close(triggerFd);
  return res;
}


x86 assembly (clang, -O0):
<read_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%esi
mov    0x2eac(%rip),%rax
or     (%rax),%esi
lea    0xeab(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1173 <read_proc+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1195 <read_proc+0x65>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea3(%rip),%rax
mov    0x2eb4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1177 <read_proc+0x47>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1040 <read@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %ebx,%eax
jmp    117c <read_proc+0x4c>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/proc/ivhs/feedback\00"
@O_RDONLY = global i32 0
@O_RSYNC = global i32 0
define i32 @read_proc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_RSYNC
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %20
13: ; preds = %1
%14 = load i32, i32* %4
%15 = load i8*, i8** %3
%16 = call i32 @read(i32 %14, i8* %15, i32 8)
store i32 %16, i32* %5
%17 = load i32, i32* %4
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %20
20: ; preds = %13, %12
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [20 x i8] c"/proc/ivhs/feedback\00"
@O_RDONLY = global i32 0
@O_RSYNC = global i32 0
define i32 @read_proc(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = load i32, i32* @O_RSYNC
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = tail call i32 @read(i32 %5, i8* %0, i32 8)
%9 = tail call i32 @close(i32 %5)
br label %10
10: ; preds = %1, %7
%11 = phi i32 [ %8, %7 ], [ -1, %1 ]
ret i32 %11
}