#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;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int empty_proc_file(char *path) {
  int empty = 0;
  char buf[36];
  int fd;
  if ((fd = open(path, O_RDONLY)) < 0 || read(fd, buf, sizeof(buf)) <= 0)
    empty = 1;
  if (fd >= 0)
    close(fd);
  return empty;
}


x86 assembly (clang, -O0):
<empty_proc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e9a(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jl     117c <empty_proc_file+0x4c>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x24,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jg     1183 <empty_proc_file+0x53>
movl   $0x1,-0xc(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     1195 <empty_proc_file+0x65>
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<empty_proc_file>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     116b <empty_proc_file+0x3b>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x24,%edx
call   1040 <read@plt>
xor    %ebp,%ebp
test   %rax,%rax
setle  %bpl
mov    %ebx,%edi
call   1030 <close@plt>
jmp    1170 <empty_proc_file+0x40>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @empty_proc_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [36 x i8]
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i32, i32* %5
%12 = getelementptr inbounds [36 x i8], [36 x i8]* %4, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 36)
%14 = icmp sle i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10, %1
store i32 1, i32* %3
br label %16
16: ; preds = %15, %10
%17 = load i32, i32* %5
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @empty_proc_file(i8* nocapture %0) {
%2 = alloca [36 x i8]
%3 = getelementptr inbounds [36 x i8], [36 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = call i64 @read(i32 %5, i8* %3, i32 36)
%9 = icmp slt i64 %8, 1
%10 = zext i1 %9 to i32
%11 = tail call i32 @close(i32 %5)
br label %12
12: ; preds = %1, %7
%13 = phi i32 [ %10, %7 ], [ 1, %1 ]
ret i32 %13
}