#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 */
struct evemu_device {
  int dummy;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int open_evemu_device(struct evemu_device *);
int read(int, char *, int);
void open_and_hold_device(struct evemu_device *dev) {
  char data[256];
  int ret;
  int fd;
  fd = open_evemu_device(dev);
  if (fd < 0)
    return;
  while ((ret = read(fd, data, sizeof(data))) > 0)
    ;
  close(fd);
}


x86 assembly (clang, -O0):
<open_and_hold_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <open_evemu_device@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jge    1160 <open_and_hold_device+0x30>
jmp    119b <open_and_hold_device+0x6b>
jmp    1165 <open_and_hold_device+0x35>
mov    -0x118(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x114(%rbp)
cmp    $0x0,%eax
jle    1190 <open_and_hold_device+0x60>
jmp    1165 <open_and_hold_device+0x35>
mov    -0x118(%rbp),%edi
call   1030 <close@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_and_hold_device>:
push   %r14
push   %rbx
sub    $0x108,%rsp
call   1050 <open_evemu_device@plt>
test   %eax,%eax
js     1174 <open_and_hold_device+0x44>
mov    %eax,%ebx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1150 <open_and_hold_device+0x20>
mov    %ebx,%edi
add    $0x108,%rsp
pop    %rbx
pop    %r14
jmp    1030 <close@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.evemu_device = type { i32 }
define void @open_and_hold_device(%struct.evemu_device* %0) {
%2 = alloca %struct.evemu_device*
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
store %struct.evemu_device* %0, %struct.evemu_device** %2
%6 = load %struct.evemu_device*, %struct.evemu_device** %2
%7 = call i32 @open_evemu_device(%struct.evemu_device* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %21
11: ; preds = %1
br label %12
12: ; preds = %17, %11
%13 = load i32, i32* %5
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = call i32 @read(i32 %13, i8* %14, i32 256)
store i32 %15, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %12
18: ; preds = %12
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %18, %10
ret void
}

LLVM IR (-O2):
%struct.evemu_device = type { i32 }
define void @open_and_hold_device(%struct.evemu_device* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @open_evemu_device(%struct.evemu_device* %0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1, %6
%7 = call i32 @read(i32 %4, i8* %3, i32 256)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %6, label %9
9: ; preds = %6
%10 = tail call i32 @close(i32 %4)
br label %11
11: ; preds = %1, %9
ret void
}