#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*/ zdtm;

/* Variables and functions */
scalar_t__ EAGAIN;
int /*<<< orphan*/ F_GETFL;
int /*<<< orphan*/ F_SETFL;
int O_NONBLOCK;
scalar_t__ errno;
int fcntl(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ test_msg(char *, char *, int, scalar_t__,
                            int /*<<< orphan*/);
int write(int, char *, int);
int fill_sock_buf(int fd) {
  int flags;
  int size;
  int ret;
  flags = fcntl(fd, F_GETFL, 0);
  if (flags == -1) {
    test_msg("ERR: %s:%d: "
             "Can't get flags"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/socket-tcpbuf.c",
             52, errno, strerror(errno));
    return -1;
  }
  if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
    test_msg("ERR: %s:%d: "
             "Can't set flags"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/socket-tcpbuf.c",
             56, errno, strerror(errno));
    return -1;
  }
  size = 0;
  while (1) {
    char zdtm[] = "zdtm test packet";
    ret = write(fd, zdtm, sizeof(zdtm));
    if (ret == -1) {
      if (errno == EAGAIN)
        break;
      test_msg("ERR: %s:%d: "
               "write"
               " (errno = %d (%s))\n",
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/"
               "test/zdtm/live/static/socket-tcpbuf.c",
               67, errno, strerror(errno));
      return -1;
    }
    size += ret;
  }
  if (fcntl(fd, F_SETFL, flags) == -1) {
    test_msg("ERR: %s:%d: "
             "Can't set flags"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/"
             "live/static/socket-tcpbuf.c",
             74, errno, strerror(errno));
    return -1;
  }
  return size;
}


x86 assembly (clang, -O0):
<fill_sock_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b3 <fill_sock_buf+0x73>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x38(%rbp),%rcx
mov    %eax,%r8d
lea    0xe6a(%rip),%rdi
lea    0xe92(%rip),%rsi
mov    $0x34,%edx
call   1050 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <fill_sock_buf+0x205>
mov    -0x8(%rbp),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
mov    0x2e1f(%rip),%rax
or     (%rax),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    1221 <fill_sock_buf+0xe1>
mov    0x2df0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
lea    0xec8(%rip),%rdi
lea    0xe24(%rip),%rsi
mov    $0x38,%edx
call   1050 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <fill_sock_buf+0x205>
movl   $0x0,-0x10(%rbp)
mov    0xef1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeee(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeec(%rip),%al
mov    %al,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x11,%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    12cc <fill_sock_buf+0x18c>
mov    0x2d64(%rip),%rax
mov    (%rax),%rax
mov    0x2d42(%rip),%rcx
cmp    (%rcx),%rax
jne    1284 <fill_sock_buf+0x144>
jmp    12da <fill_sock_buf+0x19a>
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x48(%rbp),%rcx
mov    %eax,%r8d
lea    0xe4c(%rip),%rdi
lea    0xd79(%rip),%rsi
mov    $0x43,%edx
call   1050 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <fill_sock_buf+0x205>
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1228 <fill_sock_buf+0xe8>
mov    -0x8(%rbp),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
mov    -0xc(%rbp),%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    133f <fill_sock_buf+0x1ff>
mov    0x2cd2(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x50(%rbp),%rcx
mov    %eax,%r8d
lea    0xdaa(%rip),%rdi
lea    0xd06(%rip),%rsi
mov    $0x4a,%edx
call   1050 <test_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1345 <fill_sock_buf+0x205>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_sock_buf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1239 <fill_sock_buf+0xf9>
mov    %eax,%r14d
mov    0x2e65(%rip),%r12
mov    (%r12),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
or     %r14d,%edx
mov    %ebx,%edi
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1260 <fill_sock_buf+0x120>
movaps 0xf86(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x11,%edx
call   1040 <write@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
je     11e6 <fill_sock_buf+0xa6>
mov    %rsp,%r15
nopl   0x0(%rax)
add    %eax,%ebp
movaps 0xf57(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x10(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x11,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    11c0 <fill_sock_buf+0x80>
mov    0x2de3(%rip),%r13
mov    0x0(%r13),%r15
mov    0x2dc0(%rip),%rax
cmp    (%rax),%r15
jne    128a <fill_sock_buf+0x14a>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %r14d,%edx
call   1030 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    12b5 <fill_sock_buf+0x175>
mov    0x0(%r13),%rbx
mov    %rbx,%rdi
call   1060 <strerror@plt>
lea    0xea1(%rip),%rdi
lea    0xdfd(%rip),%rsi
mov    $0x4a,%edx
jmp    1285 <fill_sock_buf+0x145>
mov    0x2d90(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1060 <strerror@plt>
lea    0xdae(%rip),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x34,%edx
jmp    1285 <fill_sock_buf+0x145>
mov    0x2d69(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1060 <strerror@plt>
lea    0xe53(%rip),%rdi
lea    0xdaf(%rip),%rsi
mov    $0x38,%edx
mov    %rbx,%rcx
jmp    12a8 <fill_sock_buf+0x168>
mov    %r15,%rdi
call   1060 <strerror@plt>
lea    0xe62(%rip),%rdi
lea    0xd8f(%rip),%rsi
mov    $0x43,%edx
mov    %r15,%rcx
mov    %eax,%r8d
call   1050 <test_msg@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_GETFL = global i32 0
@.str = [47 x i8] c"ERR: %s:%d: Can't get flags (errno = %d (%s))\0A\00"
@.str.1 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/socket-tcpbuf.c\00"
@errno = global i64 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [47 x i8] c"ERR: %s:%d: Can't set flags (errno = %d (%s))\0A\00"
@__const.fill_sock_buf.zdtm = [17 x i8] c"zdtm test packet\00"
@EAGAIN = global i64 0
@.str.3 = [37 x i8] c"ERR: %s:%d: write (errno = %d (%s))\0A\00"
define i32 @fill_sock_buf(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [17 x i8]
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = load i32, i32* @F_GETFL
%10 = call i32 @fcntl(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %1
%14 = load i64, i64* @errno
%15 = load i64, i64* @errno
%16 = call i32 @strerror(i64 %15)
%17 = call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 52, i64 %14, i32 %16)
store i32 -1, i32* %2
br label %66
18: ; preds = %1
%19 = load i32, i32* %3
%20 = load i32, i32* @F_SETFL
%21 = load i32, i32* %4
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 @fcntl(i32 %19, i32 %20, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i64, i64* @errno
%28 = load i64, i64* @errno
%29 = call i32 @strerror(i64 %28)
%30 = call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 56, i64 %27, i32 %29)
store i32 -1, i32* %2
br label %66
31: ; preds = %18
store i32 0, i32* %5
br label %32
32: ; preds = %31, %49
%33 = bitcast [17 x i8]* %7 to i8*
%34 = load i32, i32* %3
%35 = getelementptr inbounds [17 x i8], [17 x i8]* %7, i64 0, i64 0
%36 = call i32 @write(i32 %34, i8* %35, i32 17)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %49
39: ; preds = %32
%40 = load i64, i64* @errno
%41 = load i64, i64* @EAGAIN
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %44
43: ; preds = %39
br label %53
44: ; preds = %39
%45 = load i64, i64* @errno
%46 = load i64, i64* @errno
%47 = call i32 @strerror(i64 %46)
%48 = call i32 @test_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 67, i64 %45, i32 %47)
store i32 -1, i32* %2
br label %66
49: ; preds = %32
%50 = load i32, i32* %6
%51 = load i32, i32* %5
%52 = add nsw i32 %51, %50
store i32 %52, i32* %5
br label %32
53: ; preds = %43
%54 = load i32, i32* %3
%55 = load i32, i32* @F_SETFL
%56 = load i32, i32* %4
%57 = call i32 @fcntl(i32 %54, i32 %55, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %64
59: ; preds = %53
%60 = load i64, i64* @errno
%61 = load i64, i64* @errno
%62 = call i32 @strerror(i64 %61)
%63 = call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 74, i64 %60, i32 %62)
store i32 -1, i32* %2
br label %66
64: ; preds = %53
%65 = load i32, i32* %5
store i32 %65, i32* %2
br label %66
66: ; preds = %64, %59, %44, %26, %13
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
@F_GETFL = global i32 0
@.str = [47 x i8] c"ERR: %s:%d: Can't get flags (errno = %d (%s))\0A\00"
@.str.1 = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LK4D4/criu/refs/heads/master/test/zdtm/live/static/socket-tcpbuf.c\00"
@errno = global i64 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.2 = [47 x i8] c"ERR: %s:%d: Can't set flags (errno = %d (%s))\0A\00"
@__const.fill_sock_buf.zdtm = [17 x i8] c"zdtm test packet\00"
@EAGAIN = global i64 0
@.str.3 = [37 x i8] c"ERR: %s:%d: write (errno = %d (%s))\0A\00"
define i32 @fill_sock_buf(i32 %0) {
%2 = alloca [17 x i8]
%3 = load i32, i32* @F_GETFL
%4 = tail call i32 @fcntl(i32 %0, i32 %3, i32 0)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i64, i64* @errno
%8 = tail call i32 @strerror(i64 %7)
%9 = tail call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 52, i64 %7, i32 %8)
br label %46
10: ; preds = %1
%11 = load i32, i32* @F_SETFL
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %4
%14 = tail call i32 @fcntl(i32 %0, i32 %11, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
%18 = call i32 @write(i32 %0, i8* %17, i32 17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %32
20: ; preds = %10
%21 = load i64, i64* @errno
%22 = tail call i32 @strerror(i64 %21)
%23 = tail call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 56, i64 %21, i32 %22)
br label %46
24: ; preds = %32, %16
%25 = phi i32 [ 0, %16 ], [ %35, %32 ]
%26 = load i64, i64* @errno
%27 = load i64, i64* @EAGAIN
%28 = icmp eq i64 %26, %27
br i1 %28, label %38, label %29
29: ; preds = %24
%30 = tail call i32 @strerror(i64 %26)
%31 = tail call i32 @test_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 67, i64 %26, i32 %30)
br label %46
32: ; preds = %16, %32
%33 = phi i32 [ %36, %32 ], [ %18, %16 ]
%34 = phi i32 [ %35, %32 ], [ 0, %16 ]
%35 = add nsw i32 %33, %34
%36 = call i32 @write(i32 %0, i8* %17, i32 17)
%37 = icmp eq i32 %36, -1
br i1 %37, label %24, label %32
38: ; preds = %24
%39 = load i32, i32* @F_SETFL
%40 = tail call i32 @fcntl(i32 %0, i32 %39, i32 %4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i64, i64* @errno
%44 = tail call i32 @strerror(i64 %43)
%45 = tail call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.1, i64 0, i64 0), i32 74, i64 %43, i32 %44)
br label %46
46: ; preds = %29, %38, %42, %20, %6
%47 = phi i32 [ -1, %6 ], [ -1, %20 ], [ -1, %42 ], [ %25, %38 ], [ -1, %29 ]
ret i32 %47
}