#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 O_RDONLY;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ POLLOUT;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ test_file(char *, int, int /*<<< orphan*/,
                             int /*<<< orphan*/, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ test_pipe();
int main(int argc, char **argv) {
  setbuf(stdout, NULL);
  setbuf(stderr, NULL);
  test_pipe();
  test_file("/dev/null", O_RDWR, POLLIN, POLLIN, POLLOUT, POLLOUT);
  test_file("/proc/meminfo", O_RDONLY, POLLIN, POLLIN, 0, 0);
  test_file(argv[0], O_RDONLY, POLLIN, POLLIN, 0, 0);
  test_file("tmp/host_file", O_RDWR | O_CREAT | O_TRUNC, POLLIN, 0, POLLOUT,
            POLLOUT);
  printf("TEST OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <setbuf@plt>
mov    $0x0,%al
call   1030 <test_pipe@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    0x2e26(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4d(%rip),%rax
mov    (%rax),%r8d
mov    0x2e43(%rip),%rax
mov    (%rax),%r9d
lea    0xe49(%rip),%rdi
call   1060 <test_file@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    0x2deb(%rip),%rax
mov    (%rax),%ecx
lea    0xe2c(%rip),%rdi
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1060 <test_file@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
mov    0x2db7(%rip),%rax
mov    (%rax),%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
call   1060 <test_file@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%rax
or     (%rax),%esi
mov    0x2db9(%rip),%rax
or     (%rax),%esi
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
mov    0x2daf(%rip),%rax
mov    (%rax),%r8d
mov    0x2da5(%rip),%rax
mov    (%rax),%r9d
lea    0xdc3(%rip),%rdi
xor    %ecx,%ecx
call   1060 <test_file@plt>
lea    0xdc3(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <setbuf@plt>
xor    %eax,%eax
call   1030 <test_pipe@plt>
mov    0x2e56(%rip),%r12
mov    (%r12),%esi
mov    0x2e3b(%rip),%r13
mov    0x0(%r13),%ecx
mov    0x2e60(%rip),%r15
mov    (%r15),%r8d
lea    0xe66(%rip),%rdi
mov    %ecx,%edx
mov    %r8d,%r9d
call   1060 <test_file@plt>
mov    0x2e1d(%rip),%rbx
mov    (%rbx),%esi
mov    0x0(%r13),%ecx
lea    0xe52(%rip),%rdi
mov    %ecx,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <test_file@plt>
mov    (%r14),%rdi
mov    (%rbx),%esi
mov    0x0(%r13),%ecx
mov    %ecx,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <test_file@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
or     (%r12),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x0(%r13),%edx
mov    (%r15),%r8d
lea    0xe19(%rip),%rdi
xor    %ecx,%ecx
mov    %r8d,%r9d
call   1060 <test_file@plt>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@POLLIN = global i32 0
@POLLOUT = global i32 0
@.str.1 = [14 x i8] c"/proc/meminfo\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"tmp/host_file\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.3 = [9 x i8] c"TEST OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* @stdout
%7 = call i32 @setbuf(i32 %6, i32* null)
%8 = load i32, i32* @stderr
%9 = call i32 @setbuf(i32 %8, i32* null)
%10 = call i32 (...) @test_pipe()
%11 = load i32, i32* @O_RDWR
%12 = load i32, i32* @POLLIN
%13 = load i32, i32* @POLLIN
%14 = load i32, i32* @POLLOUT
%15 = load i32, i32* @POLLOUT
%16 = call i32 @test_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12, i32 %13, i32 %14, i32 %15)
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @POLLIN
%19 = load i32, i32* @POLLIN
%20 = call i32 @test_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19, i32 0, i32 0)
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = load i32, i32* @O_RDONLY
%25 = load i32, i32* @POLLIN
%26 = load i32, i32* @POLLIN
%27 = call i32 @test_file(i8* %23, i32 %24, i32 %25, i32 %26, i32 0, i32 0)
%28 = load i32, i32* @O_RDWR
%29 = load i32, i32* @O_CREAT
%30 = or i32 %28, %29
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* @POLLIN
%34 = load i32, i32* @POLLOUT
%35 = load i32, i32* @POLLOUT
%36 = call i32 @test_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %33, i32 0, i32 %34, i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@stderr = global i32 0
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
@POLLIN = global i32 0
@POLLOUT = global i32 0
@.str.1 = [14 x i8] c"/proc/meminfo\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"tmp/host_file\00"
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@str = [8 x i8] c"TEST OK\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @stdout
%4 = tail call i32 @setbuf(i32 %3, i32* null)
%5 = load i32, i32* @stderr
%6 = tail call i32 @setbuf(i32 %5, i32* null)
%7 = tail call i32 (...) @test_pipe()
%8 = load i32, i32* @O_RDWR
%9 = load i32, i32* @POLLIN
%10 = load i32, i32* @POLLOUT
%11 = tail call i32 @test_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9, i32 %9, i32 %10, i32 %10)
%12 = load i32, i32* @O_RDONLY
%13 = load i32, i32* @POLLIN
%14 = tail call i32 @test_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13, i32 %13, i32 0, i32 0)
%15 = load i8*, i8** %1
%16 = load i32, i32* @O_RDONLY
%17 = load i32, i32* @POLLIN
%18 = tail call i32 @test_file(i8* %15, i32 %16, i32 %17, i32 %17, i32 0, i32 0)
%19 = load i32, i32* @O_RDWR
%20 = load i32, i32* @O_CREAT
%21 = or i32 %20, %19
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = load i32, i32* @POLLIN
%25 = load i32, i32* @POLLOUT
%26 = tail call i32 @test_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24, i32 0, i32 %25, i32 %25)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}