#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_CREAT;
int /*<<< orphan*/ check_poll(int, int, int);
scalar_t__ close(int);
int /*<<< orphan*/ err(int, char *);
int open(char const *, int, int);
int /*<<< orphan*/ printf(char *, char const *);
scalar_t__ unlink(char const *);
void test_file(const char *path, int flags, int events1, int revents1,
               int events2, int revents2) {
  printf("testing poll() on %s...\n", path);
  int fd = open(path, flags, 0600);
  if (fd < 0)
    err(1, "open");
  if (events1)
    check_poll(fd, events1, revents1);
  if (events2)
    check_poll(fd, events2, revents2);
  if (close(fd) < 0)
    err(1, "close");
  if (flags & O_CREAT) {
    if (unlink(path) < 0)
      err(1, "unlink");
  }
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11bc <test_file+0x5c>
mov    $0x1,%edi
lea    0xe62(%rip),%rsi
call   1070 <err@plt>
cmpl   $0x0,-0x10(%rbp)
je     11d4 <test_file+0x74>
mov    -0x20(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1060 <check_poll@plt>
cmpl   $0x0,-0x18(%rbp)
je     11ec <test_file+0x8c>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1060 <check_poll@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    120f <test_file+0xaf>
mov    $0x1,%edi
lea    0xe14(%rip),%rsi
call   1070 <err@plt>
mov    -0xc(%rbp),%eax
mov    0x2ddf(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     124d <test_file+0xed>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1248 <test_file+0xe8>
mov    $0x1,%edi
lea    0xde1(%rip),%rsi
call   1070 <err@plt>
jmp    124d <test_file+0xed>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,%r13d
mov    %ecx,%r12d
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xe7a(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     120e <test_file+0xae>
test   %r14d,%r14d
je     11b6 <test_file+0x56>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %r12d,%edx
call   1060 <check_poll@plt>
test   %r13d,%r13d
je     11c9 <test_file+0x69>
mov    %ebp,%edi
mov    %r13d,%esi
mov    0x4(%rsp),%edx
call   1060 <check_poll@plt>
mov    %ebp,%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11e6 <test_file+0x86>
lea    0xe42(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
mov    0x2e0b(%rip),%rax
test   %r15d,(%rax)
je     11ff <test_file+0x9f>
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
js     1226 <test_file+0xc6>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe04(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
test   %r14d,%r14d
jne    11a9 <test_file+0x49>
jmp    11b6 <test_file+0x56>
lea    0xdf7(%rip),%rsi
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <err@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"testing poll() on %s...\0A\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"close\00"
@O_CREAT = global i32 0
@.str.3 = [7 x i8] c"unlink\00"
define void @test_file(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i8*, i8** %7
%15 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = call i32 @open(i8* %16, i32 %17, i32 384)
store i32 %18, i32* %13
%19 = load i32, i32* %13
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %6
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %6
%24 = load i32, i32* %9
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i32, i32* %13
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = call i32 @check_poll(i32 %27, i32 %28, i32 %29)
br label %31
31: ; preds = %26, %23
%32 = load i32, i32* %11
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = load i32, i32* %13
%36 = load i32, i32* %11
%37 = load i32, i32* %12
%38 = call i32 @check_poll(i32 %35, i32 %36, i32 %37)
br label %39
39: ; preds = %34, %31
%40 = load i32, i32* %13
%41 = call i64 @close(i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43, %39
%46 = load i32, i32* %8
%47 = load i32, i32* @O_CREAT
%48 = and i32 %46, %47
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %45
%51 = load i8*, i8** %7
%52 = call i64 @unlink(i8* %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %56
56: ; preds = %54, %50
br label %57
57: ; preds = %56, %45
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"testing poll() on %s...\0A\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [6 x i8] c"close\00"
@O_CREAT = global i32 0
@.str.3 = [7 x i8] c"unlink\00"
define void @test_file(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = tail call i32 @open(i8* %0, i32 %1, i32 384)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = icmp eq i32 %2, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @check_poll(i32 %8, i32 %2, i32 %3)
br label %16
16: ; preds = %14, %12
%17 = icmp eq i32 %4, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = tail call i32 @check_poll(i32 %8, i32 %4, i32 %5)
br label %20
20: ; preds = %18, %16
%21 = tail call i64 @close(i32 %8)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = load i32, i32* @O_CREAT
%27 = and i32 %26, %1
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %25
%30 = tail call i64 @unlink(i8* %0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %29, %32, %25
ret void
}