#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 /*<<< orphan*/ PF_UNIX;
int SOCK_DGRAM;
int SOCK_NONBLOCK;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int read(int, char *, int);
scalar_t__ socketpair(int /*<<< orphan*/, int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_daemon();
int /*<<< orphan*/ test_init(int, char **);
int /*<<< orphan*/ test_msg(char *, ...);
int /*<<< orphan*/ test_waitsig();
int write(int, char *, int);
int main(int argc, char **argv) {
  int sks[2], ret;
  char buf[1024];
  test_init(argc, argv);
  if (socketpair(PF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0, sks) < 0) {
    test_msg("ERR: %s:%d: "
             "socketpair"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/socket_close_data.c",
             21, errno, strerror(errno));
    return 1;
  }
  if (write(sks[1], "hello", sizeof("hello")) != sizeof("hello")) {
    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/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/socket_close_data.c",
             26, errno, strerror(errno));
    return 1;
  }
  close(sks[1]);
  test_daemon();
  test_waitsig();
  ret = read(sks[0], buf, sizeof("hello"));
  buf[ret > 0 ? ret : 0] = 0;
  if (ret != sizeof("hello")) {
    test_msg("FAIL: %s:%d: "
             "%d: %s"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/"
             "master/test/zdtm/live/static/socket_close_data.c",
             37, ret, buf, errno, strerror(errno));
    return 1;
  }
  test_msg("PASS\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <test_init@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2e02(%rip),%rax
or     (%rax),%esi
lea    -0x18(%rbp),%rcx
xor    %edx,%edx
call   10a0 <socketpair@plt>
cmp    $0x0,%rax
jge    1231 <main+0xa1>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x424(%rbp),%ecx
mov    %eax,%r8d
lea    0xdee(%rip),%rdi
lea    0xe11(%rip),%rsi
mov    $0x15,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1393 <main+0x203>
mov    -0x14(%rbp),%edi
lea    0xe9d(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
cltq
cmp    $0x6,%rax
je     129d <main+0x10d>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x428(%rbp),%ecx
mov    %eax,%r8d
lea    0xe60(%rip),%rdi
lea    0xda5(%rip),%rsi
mov    $0x1a,%edx
mov    $0x0,%al
call   1070 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1393 <main+0x203>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1050 <test_daemon@plt>
mov    $0x0,%al
call   1090 <test_waitsig@plt>
mov    -0x18(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x6,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    12e2 <main+0x152>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x42c(%rbp)
jmp    12ef <main+0x15f>
xor    %eax,%eax
mov    %eax,-0x42c(%rbp)
jmp    12ef <main+0x15f>
mov    -0x42c(%rbp),%eax
cltq
movb   $0x0,-0x420(%rbp,%rax,1)
movslq -0x1c(%rbp),%rax
cmp    $0x6,%rax
je     137e <main+0x1ee>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x43c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    0x2c9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x43c(%rbp),%ecx
mov    -0x438(%rbp),%r8
mov    -0x430(%rbp),%r9d
lea    0xda7(%rip),%rdi
lea    0xcc7(%rip),%rsi
mov    $0x25,%edx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1070 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1393 <main+0x203>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1070 <test_msg@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
call   1030 <test_init@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0x8(%rsp),%rcx
xor    %edx,%edx
call   10a0 <socketpair@plt>
test   %rax,%rax
js     1236 <main+0xa6>
mov    0xc(%rsp),%edi
lea    0xf03(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
cmp    $0x6,%eax
jne    125b <main+0xcb>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <test_daemon@plt>
xor    %eax,%eax
call   1090 <test_waitsig@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x6,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
mov    $0x0,%eax
cmovns %ebp,%eax
movb   $0x0,0x10(%rsp,%rax,1)
cmp    $0x6,%ebp
jne    129b <main+0x10b>
lea    0xefd(%rip),%rdi
xor    %eax,%eax
call   1070 <test_msg@plt>
jmp    128f <main+0xff>
mov    0x2d8b(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xdb3(%rip),%rdi
lea    0xdd6(%rip),%rsi
mov    $0x15,%edx
jmp    127e <main+0xee>
mov    0x2d66(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xe6c(%rip),%rdi
lea    0xdb1(%rip),%rsi
mov    $0x1a,%edx
mov    %ebx,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <test_msg@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d26(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
mov    %eax,(%rsp)
lea    0xe4e(%rip),%rdi
lea    0xd6e(%rip),%rsi
lea    0x10(%rsp),%r8
mov    $0x25,%edx
mov    %ebp,%ecx
mov    %ebx,%r9d
xor    %eax,%eax
call   1070 <test_msg@plt>
jmp    128a <main+0xfa>

LLVM IR (-O0):
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str = [42 x i8] c"ERR: %s:%d: socketpair (errno = %d (%s))\0A\00"
@.str.1 = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/socket_close_data.c\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [37 x i8] c"ERR: %s:%d: write (errno = %d (%s))\0A\00"
@.str.4 = [39 x i8] c"FAIL: %s:%d: %d: %s (errno = %d (%s))\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @test_init(i32 %9, i8** %10)
%12 = load i32, i32* @PF_UNIX
%13 = load i32, i32* @SOCK_DGRAM
%14 = load i32, i32* @SOCK_NONBLOCK
%15 = or i32 %13, %14
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i64 @socketpair(i32 %12, i32 %15, i32 0, i32* %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %2
%20 = load i32, i32* @errno
%21 = load i32, i32* @errno
%22 = call i32 @strerror(i32 %21)
%23 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 21, i32 %20, i32 %22)
store i32 1, i32* %3
br label %66
24: ; preds = %2
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @write(i32 %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%28 = sext i32 %27 to i64
%29 = icmp ne i64 %28, 6
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i32, i32* @errno
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 26, i32 %31, i32 %33)
store i32 1, i32* %3
br label %66
35: ; preds = %24
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = call i32 (...) @test_daemon()
%40 = call i32 (...) @test_waitsig()
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 6)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %35
%48 = load i32, i32* %7
br label %50
49: ; preds = %35
br label %50
50: ; preds = %49, %47
%51 = phi i32 [ %48, %47 ], [ 0, %49 ]
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %52
store i8 0, i8* %53
%54 = load i32, i32* %7
%55 = sext i32 %54 to i64
%56 = icmp ne i64 %55, 6
br i1 %56, label %57, label %64
57: ; preds = %50
%58 = load i32, i32* %7
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%60 = load i32, i32* @errno
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 37, i32 %58, i8* %59, i32 %60, i32 %62)
store i32 1, i32* %3
br label %66
64: ; preds = %50
%65 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %66
66: ; preds = %64, %57, %30, %19
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@PF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str = [42 x i8] c"ERR: %s:%d: socketpair (errno = %d (%s))\0A\00"
@.str.1 = [174 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AuthenticEshkinKot/criu/refs/heads/master/test/zdtm/live/static/socket_close_data.c\00"
@errno = global i32 0
@.str.2 = [6 x i8] c"hello\00"
@.str.3 = [37 x i8] c"ERR: %s:%d: write (errno = %d (%s))\0A\00"
@.str.4 = [39 x i8] c"FAIL: %s:%d: %d: %s (errno = %d (%s))\0A\00"
@.str.5 = [6 x i8] c"PASS\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @test_init(i32 %0, i8** %1)
%8 = load i32, i32* @PF_UNIX
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @SOCK_NONBLOCK
%11 = or i32 %10, %9
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = call i64 @socketpair(i32 %8, i32 %11, i32 0, i32* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 21, i32 %16, i32 %17)
br label %46
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 6)
%23 = icmp eq i32 %22, 6
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 26, i32 %25, i32 %26)
br label %46
28: ; preds = %19
%29 = load i32, i32* %20
%30 = call i32 @close(i32 %29)
%31 = call i32 (...) @test_daemon()
%32 = call i32 (...) @test_waitsig()
%33 = load i32, i32* %12
%34 = call i32 @read(i32 %33, i8* %6, i32 6)
%35 = icmp sgt i32 %34, 0
%36 = select i1 %35, i32 %34, i32 0
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %37
store i8 0, i8* %38
%39 = icmp eq i32 %34, 6
br i1 %39, label %44, label %40
40: ; preds = %28
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([174 x i8], [174 x i8]* @.str.1, i64 0, i64 0), i32 37, i32 %34, i8* %6, i32 %41, i32 %42)
br label %46
44: ; preds = %28
%45 = call i32 (i8*, ...) @test_msg(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %40, %24, %15
%47 = phi i32 [ 1, %15 ], [ 1, %24 ], [ 1, %40 ], [ 0, %44 ]
ret i32 %47
}