#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*/ zeroes;
typedef scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ abort();
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ vsd_set_nonblocking();
int /*<<< orphan*/ vsd_wait_nonblock_write();
int vsd_write(char *, int, int /*<<< orphan*/);
void test_vsd_poll(void) {
  char zeroes[10] = {};
  if (!(!vsd_set_nonblocking())) {
    fprintf(stderr, "%s %d\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/eabatalov/au-linux-kernel-autumn-2017/"
            "refs/heads/master/tasks/vsd4/vsd_userspace/vsd_test.c",
            128);
    perror("Test failed");
    abort();
  };
  while (1) {
    ssize_t ret = vsd_write(zeroes, sizeof(zeroes), 0);
    if ((ret < 0) && (errno == EAGAIN)) {
      break;
    }
  }
  if (!(!vsd_wait_nonblock_write())) {
    fprintf(stderr, "%s %d\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/eabatalov/au-linux-kernel-autumn-2017/"
            "refs/heads/master/tasks/vsd4/vsd_userspace/vsd_test.c",
            137);
    perror("Test failed");
    abort();
  };
  if (!(vsd_write(zeroes, sizeof(zeroes), 0) == sizeof(zeroes))) {
    fprintf(stderr, "%s %d\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/eabatalov/au-linux-kernel-autumn-2017/"
            "refs/heads/master/tasks/vsd4/vsd_userspace/vsd_test.c",
            138);
    perror("Test failed");
    abort();
  };
}


x86 assembly (clang, -O0):
<test_vsd_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0xa(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    $0x0,%al
call   1070 <vsd_set_nonblocking@plt>
cmp    $0x0,%eax
je     11cc <test_vsd_poll+0x5c>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xe58(%rip),%rdx
mov    $0x80,%ecx
call   1060 <fprintf@plt>
lea    0xefd(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11d1 <test_vsd_poll+0x61>
lea    -0xa(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1090 <vsd_write@plt>
cltq
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1211 <test_vsd_poll+0xa1>
mov    0x2ddf(%rip),%rax
mov    (%rax),%rax
mov    0x2dc5(%rip),%rcx
cmp    (%rcx),%rax
jne    1211 <test_vsd_poll+0xa1>
jmp    1216 <test_vsd_poll+0xa6>
jmp    11d1 <test_vsd_poll+0x61>
mov    $0x0,%al
call   1050 <vsd_wait_nonblock_write@plt>
cmp    $0x0,%eax
je     125a <test_vsd_poll+0xea>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
lea    0xdca(%rip),%rdx
mov    $0x89,%ecx
call   1060 <fprintf@plt>
lea    0xe6f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0xa(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1090 <vsd_write@plt>
cltq
cmp    $0xa,%rax
je     12aa <test_vsd_poll+0x13a>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
lea    0xd7a(%rip),%rdx
mov    $0x8a,%ecx
call   1060 <fprintf@plt>
lea    0xe1f(%rip),%rdi
call   1080 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_vsd_poll>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movw   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1060 <vsd_set_nonblocking@plt>
test   %eax,%eax
jne    11e4 <test_vsd_poll+0x84>
mov    %rsp,%rbx
mov    0x2e4b(%rip),%r14
mov    0x2e34(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <vsd_write@plt>
test   %eax,%eax
jns    11a0 <test_vsd_poll+0x40>
mov    (%r14),%rax
cmp    (%r15),%rax
jne    11a0 <test_vsd_poll+0x40>
xor    %eax,%eax
call   1040 <vsd_wait_nonblock_write@plt>
test   %eax,%eax
jne    1202 <test_vsd_poll+0xa2>
mov    %rsp,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1080 <vsd_write@plt>
cmp    $0xa,%eax
jne    1220 <test_vsd_poll+0xc0>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
lea    0xe0c(%rip),%rdx
mov    $0x80,%ecx
jmp    123c <test_vsd_poll+0xdc>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
lea    0xdee(%rip),%rdx
mov    $0x89,%ecx
jmp    123c <test_vsd_poll+0xdc>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
lea    0xdd0(%rip),%rdx
mov    $0x8a,%ecx
call   1050 <fprintf@plt>
lea    0xe75(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
@.str.1 = [182 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/eabatalov/au-linux-kernel-autumn-2017/refs/heads/master/tasks/vsd4/vsd_userspace/vsd_test.c\00"
@.str.2 = [12 x i8] c"Test failed\00"
@errno = global i64 0
@EAGAIN = global i64 0
define void @test_vsd_poll() {
%1 = alloca [10 x i8]
%2 = alloca i64
%3 = bitcast [10 x i8]* %1 to i8*
%4 = call i32 (...) @vsd_set_nonblocking()
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 128)
%9 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %0
br label %12
12: ; preds = %11, %23
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%14 = call i32 @vsd_write(i8* %13, i32 10, i32 0)
%15 = sext i32 %14 to i64
store i64 %15, i64* %2
%16 = load i64, i64* %2
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %24
23: ; preds = %18, %12
br label %12
24: ; preds = %22
%25 = call i32 (...) @vsd_wait_nonblock_write()
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 137)
%30 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %24
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%34 = call i32 @vsd_write(i8* %33, i32 10, i32 0)
%35 = sext i32 %34 to i64
%36 = icmp eq i64 %35, 10
br i1 %36, label %42, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 138)
%40 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %32
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [7 x i8] c"%s %d\0A\00"
@.str.1 = [182 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/eabatalov/au-linux-kernel-autumn-2017/refs/heads/master/tasks/vsd4/vsd_userspace/vsd_test.c\00"
@.str.2 = [12 x i8] c"Test failed\00"
@errno = global i64 0
@EAGAIN = global i64 0
define void @test_vsd_poll() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @vsd_set_nonblocking()
%4 = icmp eq i32 %3, 0
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 128)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 (...) @abort()
unreachable
10: ; preds = %0, %13
%11 = call i32 @vsd_write(i8* %2, i32 10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10, %14
br label %10
14: ; preds = %10
%15 = load i64, i64* @errno
%16 = load i64, i64* @EAGAIN
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %13
18: ; preds = %14
%19 = call i32 (...) @vsd_wait_nonblock_write()
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 137)
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %18
%27 = call i32 @vsd_write(i8* %2, i32 10, i32 0)
%28 = icmp eq i32 %27, 10
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([182 x i8], [182 x i8]* @.str.1, i64 0, i64 0), i32 138)
%32 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %26
ret void
}