#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 */
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ connect(int, void *, int);
int /*<<< orphan*/ errno;
int send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_msg(char *, char *, int, char const *,
                            int /*<<< orphan*/, int /*<<< orphan*/);
int client(const char *iter) {
  struct sockaddr_un addr;
  int sk;
  sk = socket(AF_UNIX, SOCK_DGRAM, 0);
  if (sk < 0) {
    test_msg("ERR: %s:%d: "
             "open client %s"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/socket_close_data01.c",
             25, iter, errno, strerror(errno));
    return 1;
  }
  addr.sun_family = AF_UNIX;
  strcpy(addr.sun_path, "socket_close_data01.sock");
  if (connect(sk, (void *)&addr, sizeof(struct sockaddr_un)) < 0) {
    test_msg("ERR: %s:%d: "
             "connect failed %s\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/socket_close_data01.c",
             33, iter, errno, strerror(errno));
    return 1;
  }
  if (send(sk, "hello", sizeof("hello"), 0) != sizeof("hello")) {
    test_msg("ERR: %s:%d: "
             "send failed %s\n"
             " (errno = %d (%s))\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/fbocharov/criu/refs/heads/master/test/"
             "zdtm/live/static/socket_close_data01.c",
             38, iter, errno, strerror(errno));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11e3 <client+0x83>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%r8d
mov    %eax,%r9d
lea    0xe3a(%rip),%rdi
lea    0xe61(%rip),%rsi
mov    $0x19,%edx
call   1050 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <client+0x184>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    0xedc(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1060 <connect@plt>
cmp    $0x0,%rax
jge    126a <client+0x10a>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x38(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
mov    %eax,%r9d
lea    0xea1(%rip),%rdi
lea    0xdda(%rip),%rsi
mov    $0x21,%edx
call   1050 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <client+0x184>
mov    -0x1c(%rbp),%edi
lea    0xeac(%rip),%rsi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cltq
cmp    $0x6,%rax
je     12dd <client+0x17d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%rcx
mov    -0x3c(%rbp),%r8d
mov    %eax,%r9d
lea    0xe66(%rip),%rdi
lea    0xd67(%rip),%rsi
mov    $0x26,%edx
call   1050 <test_msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <client+0x184>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
mov    0x2e76(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
test   %eax,%eax
js     11f7 <client+0x97>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
lea    0xf3e(%rip),%rsi
call   1030 <strcpy@plt>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x8,%edx
call   1060 <connect@plt>
test   %rax,%rax
js     121c <client+0xbc>
lea    0xf67(%rip),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    $0x6,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0x6,%eax
je     1252 <client+0xf2>
mov    0x2df7(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xf3d(%rip),%rdi
lea    0xe3e(%rip),%rsi
mov    $0x26,%edx
jmp    123f <client+0xdf>
mov    0x2dd2(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xdf2(%rip),%rdi
lea    0xe19(%rip),%rsi
mov    $0x19,%edx
jmp    123f <client+0xdf>
mov    0x2dad(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xebb(%rip),%rdi
lea    0xdf4(%rip),%rsi
mov    $0x21,%edx
mov    %r14,%rcx
mov    %ebx,%r8d
mov    %eax,%r9d
call   1050 <test_msg@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [46 x i8] c"ERR: %s:%d: open client %s (errno = %d (%s))\0A\00"
@.str.1 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fbocharov/criu/refs/heads/master/test/zdtm/live/static/socket_close_data01.c\00"
@errno = global i32 0
@.str.2 = [25 x i8] c"socket_close_data01.sock\00"
@.str.3 = [50 x i8] c"ERR: %s:%d: connect failed %s\0A (errno = %d (%s))\0A\00"
@.str.4 = [6 x i8] c"hello\00"
@.str.5 = [47 x i8] c"ERR: %s:%d: send failed %s\0A (errno = %d (%s))\0A\00"
define i32 @client(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.sockaddr_un
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @AF_UNIX
%7 = load i32, i32* @SOCK_DGRAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i32, i32* @errno
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* %12, i32 %13, i32 %15)
store i32 1, i32* %2
br label %45
17: ; preds = %1
%18 = load i32, i32* @AF_UNIX
%19 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %4, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @strcpy(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %5
%24 = bitcast %struct.sockaddr_un* %4 to i8*
%25 = call i64 @connect(i32 %23, i8* %24, i32 8)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %17
%28 = load i8*, i8** %3
%29 = load i32, i32* @errno
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 @test_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* %28, i32 %29, i32 %31)
store i32 1, i32* %2
br label %45
33: ; preds = %17
%34 = load i32, i32* %5
%35 = call i32 @send(i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 0)
%36 = sext i32 %35 to i64
%37 = icmp ne i64 %36, 6
br i1 %37, label %38, label %44
38: ; preds = %33
%39 = load i8*, i8** %3
%40 = load i32, i32* @errno
%41 = load i32, i32* @errno
%42 = call i32 @strerror(i32 %41)
%43 = call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 38, i8* %39, i32 %40, i32 %42)
store i32 1, i32* %2
br label %45
44: ; preds = %33
store i32 0, i32* %2
br label %45
45: ; preds = %44, %38, %27, %11
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
@AF_UNIX = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [46 x i8] c"ERR: %s:%d: open client %s (errno = %d (%s))\0A\00"
@.str.1 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/fbocharov/criu/refs/heads/master/test/zdtm/live/static/socket_close_data01.c\00"
@errno = global i32 0
@.str.2 = [25 x i8] c"socket_close_data01.sock\00"
@.str.3 = [50 x i8] c"ERR: %s:%d: connect failed %s\0A (errno = %d (%s))\0A\00"
@.str.4 = [6 x i8] c"hello\00"
@.str.5 = [47 x i8] c"ERR: %s:%d: send failed %s\0A (errno = %d (%s))\0A\00"
define i32 @client(i8* %0) {
%2 = alloca %struct.sockaddr_un
%3 = bitcast %struct.sockaddr_un* %2 to i8*
%4 = load i32, i32* @AF_UNIX
%5 = load i32, i32* @SOCK_DGRAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 @test_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* %0, i32 %9, i32 %10)
br label %29
12: ; preds = %1
%13 = load i32, i32* @AF_UNIX
%14 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %2, i64 0, i32 1
store i32 %13, i32* %14
%15 = tail call i32 @strcpy(i32 undef, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%16 = call i64 @connect(i32 %6, i8* %3, i32 8)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 @test_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 33, i8* %0, i32 %19, i32 %20)
br label %29
22: ; preds = %12
%23 = call i32 @send(i32 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 6, i32 0)
%24 = icmp eq i32 %23, 6
br i1 %24, label %29, label %25
25: ; preds = %22
%26 = load i32, i32* @errno
%27 = call i32 @strerror(i32 %26)
%28 = call i32 @test_msg(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.1, i64 0, i64 0), i32 38, i8* %0, i32 %26, i32 %27)
br label %29
29: ; preds = %22, %25, %18, %8
%30 = phi i32 [ 1, %8 ], [ 1, %18 ], [ 1, %25 ], [ 0, %22 ]
ret i32 %30
}