#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 uint8_t;
struct sockaddr_un {
  int /*<<< orphan*/ sun_path;
  int /*<<< orphan*/ sun_family;
};
struct sockaddr {
  int dummy;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ AF_UNIX;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr const *, int);
scalar_t__ errno;
int /*<<< orphan*/ error(int /*<<< orphan*/, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ memset(struct sockaddr_un *, int /*<<< orphan*/, int);
int read(int, int **, scalar_t__);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int);
int write(int, int **, int);
void testDie() {
  int ret, sock, len, type;
  ssize_t written;
  struct sockaddr_un addr;
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
  if (sock < 0)
    error(EXIT_FAILURE, errno, "die socket");
  memset(&addr, 0, sizeof(struct sockaddr_un));
  addr.sun_family = AF_UNIX;
  strncpy(addr.sun_path, "/tmp/mysocket", sizeof(addr.sun_path) - 1);
  ret =
      connect(sock, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un));
  if (ret < 0)
    error(EXIT_FAILURE, errno, "die connect");
  uint8_t data[] = {0, 0, 0xFF, 0xFF};
  written = write(sock, &data, sizeof(data));
  if (written < sizeof(data))
    error(EXIT_FAILURE, errno, "die write");
  uint8_t resp[256];
  errno = 0;
  ret = read(sock, &resp, 2 + 2 + 0);
  if (ret != 2 + 2 + 0)
    error(EXIT_FAILURE, errno, "die read response 2");
  len = (resp[0] << 8) | resp[1];
  if (len != 0)
    error(EXIT_FAILURE, 0, "unexpected close length %d", len);
  type = (resp[2] << 8) | resp[3];
  if (type != 0xFFFF)
    error(EXIT_FAILURE, 0, "unexpected close type %d", type);
  close(sock);
}


x86 assembly (clang, -O0):
<testDie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d4 <testDie+0x54>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    0x2e0f(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0xe33(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    0xe11(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1245 <testDie+0xc5>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    0x2d9e(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0xddb(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
mov    0xe34(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe31(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1040 <write@plt>
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x10,%rax
jae    12a0 <testDie+0x120>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0xd8c(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
mov    0x2d29(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     12f2 <testDie+0x172>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%rax
mov    %eax,%esi
lea    0xd44(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
mov    -0x430(%rbp),%eax
shl    $0x8,%eax
or     -0x42c(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     132a <testDie+0x1aa>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%ecx
xor    %esi,%esi
lea    0xd20(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
mov    -0x428(%rbp),%eax
shl    $0x8,%eax
or     -0x424(%rbp),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xffff,-0x10(%rbp)
je     1365 <testDie+0x1e5>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%ecx
xor    %esi,%esi
lea    0xd00(%rip),%rdx
mov    $0x0,%al
call   1080 <error@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testDie>:
push   %rbp
push   %r14
push   %rbx
sub    $0x420,%rsp
mov    0x2e56(%rip),%r14
mov    (%r14),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11cb <testDie+0x4b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
lea    0xe3c(%rip),%rdx
xor    %eax,%eax
call   1080 <error@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    0x8(%rsp),%edi
lea    0xe1a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1090 <connect@plt>
test   %eax,%eax
jns    122e <testDie+0xae>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    0xdf2(%rip),%rdx
xor    %eax,%eax
call   1080 <error@plt>
movaps 0xe4b(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x10,%edx
call   1040 <write@plt>
cmp    $0xf,%eax
ja     1270 <testDie+0xf0>
mov    0x2d71(%rip),%rax
mov    (%rax),%edi
mov    0x2d70(%rip),%rax
mov    (%rax),%esi
lea    0xdbc(%rip),%rdx
xor    %eax,%eax
call   1080 <error@plt>
mov    0x2d59(%rip),%rbx
movq   $0x0,(%rbx)
lea    0x20(%rsp),%rsi
mov    $0x4,%edx
mov    %ebp,%edi
call   1070 <read@plt>
cmp    $0x4,%eax
je     12ad <testDie+0x12d>
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%esi
lea    0xd89(%rip),%rdx
xor    %eax,%eax
call   1080 <error@plt>
mov    0x20(%rsp),%ecx
shl    $0x8,%ecx
or     0x24(%rsp),%ecx
je     12d3 <testDie+0x153>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1080 <error@plt>
mov    0x28(%rsp),%ecx
shl    $0x8,%ecx
or     0x2c(%rsp),%ecx
cmp    $0xffff,%ecx
je     12ff <testDie+0x17f>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1080 <error@plt>
mov    %ebp,%edi
call   1060 <close@plt>
add    $0x420,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str = [11 x i8] c"die socket\00"
@.str.1 = [14 x i8] c"/tmp/mysocket\00"
@.str.2 = [12 x i8] c"die connect\00"
@__const.testDie.data = [4 x i32] [i32 0, i32 0, i32 255, i32 255]
@.str.3 = [10 x i8] c"die write\00"
@.str.4 = [20 x i8] c"die read response 2\00"
@.str.5 = [27 x i8] c"unexpected close length %d\00"
@.str.6 = [25 x i8] c"unexpected close type %d\00"
define void @testDie() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_un
%7 = alloca [4 x i32]
%8 = alloca [256 x i32]
%9 = load i32, i32* @AF_UNIX
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %2
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %0
%15 = load i32, i32* @EXIT_FAILURE
%16 = load i64, i64* @errno
%17 = trunc i64 %16 to i32
%18 = call i32 (i32, i32, i8*, ...) @error(i32 %15, i32 %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %14, %0
%20 = call i32 @memset(%struct.sockaddr_un* %6, i32 0, i32 8)
%21 = load i32, i32* @AF_UNIX
%22 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @strncpy(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 3)
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_un* %6 to %struct.sockaddr*
%28 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 8)
store i32 %28, i32* %1
%29 = load i32, i32* %1
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %19
%32 = load i32, i32* @EXIT_FAILURE
%33 = load i64, i64* @errno
%34 = trunc i64 %33 to i32
%35 = call i32 (i32, i32, i8*, ...) @error(i32 %32, i32 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %31, %19
%37 = bitcast [4 x i32]* %7 to i8*
%38 = load i32, i32* %2
%39 = bitcast [4 x i32]* %7 to i32**
%40 = call i32 @write(i32 %38, i32** %39, i32 16)
store i32 %40, i32* %5
%41 = load i32, i32* %5
%42 = sext i32 %41 to i64
%43 = icmp ult i64 %42, 16
br i1 %43, label %44, label %49
44: ; preds = %36
%45 = load i32, i32* @EXIT_FAILURE
%46 = load i64, i64* @errno
%47 = trunc i64 %46 to i32
%48 = call i32 (i32, i32, i8*, ...) @error(i32 %45, i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %44, %36
store i64 0, i64* @errno
%50 = load i32, i32* %2
%51 = bitcast [256 x i32]* %8 to i32**
%52 = call i32 @read(i32 %50, i32** %51, i64 4)
store i32 %52, i32* %1
%53 = load i32, i32* %1
%54 = icmp ne i32 %53, 4
br i1 %54, label %55, label %60
55: ; preds = %49
%56 = load i32, i32* @EXIT_FAILURE
%57 = load i64, i64* @errno
%58 = trunc i64 %57 to i32
%59 = call i32 (i32, i32, i8*, ...) @error(i32 %56, i32 %58, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %55, %49
%61 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 0
%62 = load i32, i32* %61
%63 = shl i32 %62, 8
%64 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 1
%65 = load i32, i32* %64
%66 = or i32 %63, %65
store i32 %66, i32* %3
%67 = load i32, i32* %3
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %73
69: ; preds = %60
%70 = load i32, i32* @EXIT_FAILURE
%71 = load i32, i32* %3
%72 = call i32 (i32, i32, i8*, ...) @error(i32 %70, i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %71)
br label %73
73: ; preds = %69, %60
%74 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 2
%75 = load i32, i32* %74
%76 = shl i32 %75, 8
%77 = getelementptr inbounds [256 x i32], [256 x i32]* %8, i64 0, i64 3
%78 = load i32, i32* %77
%79 = or i32 %76, %78
store i32 %79, i32* %4
%80 = load i32, i32* %4
%81 = icmp ne i32 %80, 65535
br i1 %81, label %82, label %86
82: ; preds = %73
%83 = load i32, i32* @EXIT_FAILURE
%84 = load i32, i32* %4
%85 = call i32 (i32, i32, i8*, ...) @error(i32 %83, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %82, %73
%87 = load i32, i32* %2
%88 = call i32 @close(i32 %87)
ret void
}

LLVM IR (-O2):
%struct.sockaddr_un = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_UNIX = global i32 0
@SOCK_STREAM = global i32 0
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@.str = [11 x i8] c"die socket\00"
@.str.1 = [14 x i8] c"/tmp/mysocket\00"
@.str.2 = [12 x i8] c"die connect\00"
@__const.testDie.data = [4 x i32] [i32 0, i32 0, i32 255, i32 255]
@.str.3 = [10 x i8] c"die write\00"
@.str.4 = [20 x i8] c"die read response 2\00"
@.str.5 = [27 x i8] c"unexpected close length %d\00"
@.str.6 = [25 x i8] c"unexpected close type %d\00"
define void @testDie() {
%1 = alloca %struct.sockaddr_un
%2 = alloca [4 x i32]
%3 = alloca [256 x i32]
%4 = bitcast %struct.sockaddr_un* %1 to i8*
%5 = load i32, i32* @AF_UNIX
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %0
%10 = load i32, i32* @EXIT_FAILURE
%11 = load i64, i64* @errno
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i32, i32, i8*, ...) @error(i32 %10, i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %9, %0
%15 = call i32 @memset(%struct.sockaddr_un* %1, i32 0, i32 8)
%16 = load i32, i32* @AF_UNIX
%17 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_un, %struct.sockaddr_un* %1, i64 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @strncpy(i32 %19, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 3)
%21 = bitcast %struct.sockaddr_un* %1 to %struct.sockaddr*
%22 = call i32 @connect(i32 %7, %struct.sockaddr* %21, i32 8)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i32, i32* @EXIT_FAILURE
%26 = load i64, i64* @errno
%27 = trunc i64 %26 to i32
%28 = call i32 (i32, i32, i8*, ...) @error(i32 %25, i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %24, %14
%30 = bitcast [4 x i32]* %2 to i8*
%31 = bitcast [4 x i32]* %2 to i32**
%32 = call i32 @write(i32 %7, i32** %31, i32 16)
%33 = icmp ult i32 %32, 16
br i1 %33, label %34, label %39
34: ; preds = %29
%35 = load i32, i32* @EXIT_FAILURE
%36 = load i64, i64* @errno
%37 = trunc i64 %36 to i32
%38 = call i32 (i32, i32, i8*, ...) @error(i32 %35, i32 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %39
39: ; preds = %34, %29
%40 = bitcast [256 x i32]* %3 to i8*
store i64 0, i64* @errno
%41 = bitcast [256 x i32]* %3 to i32**
%42 = call i32 @read(i32 %7, i32** %41, i64 4)
%43 = icmp eq i32 %42, 4
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i32, i32* @EXIT_FAILURE
%46 = load i64, i64* @errno
%47 = trunc i64 %46 to i32
%48 = call i32 (i32, i32, i8*, ...) @error(i32 %45, i32 %47, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %44, %39
%50 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 0
%51 = load i32, i32* %50
%52 = shl i32 %51, 8
%53 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 1
%54 = load i32, i32* %53
%55 = or i32 %52, %54
%56 = icmp eq i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %49
%58 = load i32, i32* @EXIT_FAILURE
%59 = call i32 (i32, i32, i8*, ...) @error(i32 %58, i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %60
60: ; preds = %57, %49
%61 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 2
%62 = load i32, i32* %61
%63 = shl i32 %62, 8
%64 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 3
%65 = load i32, i32* %64
%66 = or i32 %63, %65
%67 = icmp eq i32 %66, 65535
br i1 %67, label %71, label %68
68: ; preds = %60
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 (i32, i32, i8*, ...) @error(i32 %69, i32 0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %66)
br label %71
71: ; preds = %68, %60
%72 = call i32 @close(i32 %7)
ret void
}