#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ data;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ MSG_DONTROUTE;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ assert(int);
scalar_t__ bind(int /*<<< orphan*/, struct sockaddr *, int);
scalar_t__ close(int);
scalar_t__ connect(int /*<<< orphan*/, struct sockaddr *, int);
scalar_t__ fork();
scalar_t__ getsockname(int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
scalar_t__ listen(int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int /*<<< orphan*/, char const *, size_t const, int /*<<< orphan*/);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  static const char data[] = "data";
  const size_t size = sizeof(data) - 1;
  struct sockaddr_in addr;
  socklen_t len = sizeof(addr);
  pid_t pid;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  close(0);
  close(1);
  assert(socket(PF_INET, SOCK_STREAM, 0) == 0);
  assert(bind(0, (struct sockaddr *)&addr, len) == 0);
  assert(listen(0, 5) == 0);
  memset(&addr, 0, sizeof(addr));
  assert(getsockname(0, (struct sockaddr *)&addr, &len) == 0);
  assert((pid = fork()) >= 0);
  if (pid) {
    char buf[sizeof(data)];
    int status;
    assert(accept(0, (struct sockaddr *)&addr, &len) == 1);
    assert(close(0) == 0);
    assert(recv(1, buf, sizeof(buf), MSG_WAITALL) == (int)size);
    assert(waitpid(pid, &status, 0) == pid);
    assert(status == 0);
    assert(close(1) == 0);
  } else {
    assert(close(0) == 0);
    assert(socket(PF_INET, SOCK_STREAM, 0) == 0);
    assert(connect(0, (struct sockaddr *)&addr, len) == 0);
    assert(send(0, data, size, MSG_DONTROUTE) == (int)size);
    assert(close(0) == 0);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x4,-0x10(%rbp)
movl   $0x8,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %edi,%edi
call   10a0 <bind@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %edi,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    -0x18(%rbp),%rsi
xor    %edi,%edi
lea    -0x1c(%rbp),%rdx
call   10d0 <getsockname@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
je     13ad <main+0x1cd>
lea    -0x18(%rbp),%rsi
xor    %edi,%edi
lea    -0x1c(%rbp),%rdx
call   10c0 <accept@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %edi,%edi
call   1070 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x2d(%rbp),%rsi
mov    0x2c75(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <recv@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    -0x28(%rbp),%rdi
lea    -0x34(%rbp),%rsi
xor    %edx,%edx
call   10b0 <waitpid@plt>
cmp    -0x28(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x0,-0x34(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    $0x1,%edi
call   1070 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
jmp    1452 <main+0x272>
xor    %edi,%edi
call   1070 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
lea    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %edi,%edi
call   10e0 <connect@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
mov    0x2bcb(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
lea    0xbe0(%rip),%rsi
mov    $0x4,%edx
call   1040 <send@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %edi,%edi
call   1070 <close@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movl   $0x8,0x4(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x8(%rsp)
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x2d84(%rip),%r14
mov    (%r14),%edi
mov    0x2d82(%rip),%r15
mov    (%r15),%esi
xor    %edx,%edx
call   1100 <socket@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x8,%edx
call   10a0 <bind@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
lea    0x4(%rsp),%rdx
xor    %edi,%edi
mov    %rbx,%rsi
call   10d0 <getsockname@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %rax,%rbx
mov    %rax,%rdi
shr    $0x3f,%rdi
xor    $0x1,%edi
call   1080 <assert@plt>
test   %rbx,%rbx
je     1376 <main+0x196>
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
xor    %edi,%edi
call   10c0 <accept@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
call   1070 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x2c92(%rip),%rax
mov    (%rax),%ecx
lea    0x1b(%rsp),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <recv@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
lea    0x14(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   10b0 <waitpid@plt>
xor    %edi,%edi
cmp    %rbx,%rax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x14(%rsp)
sete   %dil
call   1080 <assert@plt>
mov    $0x1,%edi
jmp    13f0 <main+0x210>
xor    %edi,%edi
call   1070 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   1100 <socket@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x4(%rsp),%edx
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   10e0 <connect@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%ecx
lea    0xc2c(%rip),%rsi
mov    $0x4,%edx
xor    %edi,%edi
call   1040 <send@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1080 <assert@plt>
xor    %edi,%edi
call   1070 <close@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1080 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.data = internal constant [5 x i8] c"data\00"
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_WAITALL = global i32 0
@MSG_DONTROUTE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i64
%6 = alloca [5 x i8]
%7 = alloca i32
store i32 0, i32* %1
store i64 4, i64* %2
store i32 8, i32* %4
%8 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 8)
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_LOOPBACK
%12 = call i32 @htonl(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = call i64 @close(i32 0)
%16 = call i64 @close(i32 1)
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i64 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = load i32, i32* %4
%25 = call i64 @bind(i32 0, %struct.sockaddr* %23, i32 %24)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i64 @listen(i32 0, i32 5)
%30 = icmp eq i64 %29, 0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 8)
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i64 @getsockname(i32 0, %struct.sockaddr* %34, i32* %4)
%36 = icmp eq i64 %35, 0
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
%39 = call i64 (...) @fork()
store i64 %39, i64* %5
%40 = icmp sge i64 %39, 0
%41 = zext i1 %40 to i32
%42 = call i32 @assert(i32 %41)
%43 = load i64, i64* %5
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %75
45: ; preds = %0
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i32 @accept(i32 0, %struct.sockaddr* %46, i32* %4)
%48 = icmp eq i32 %47, 1
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = call i64 @close(i32 0)
%52 = icmp eq i64 %51, 0
%53 = zext i1 %52 to i32
%54 = call i32 @assert(i32 %53)
%55 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%56 = load i32, i32* @MSG_WAITALL
%57 = call i32 @recv(i32 1, i8* %55, i32 5, i32 %56)
%58 = icmp eq i32 %57, 4
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i64, i64* %5
%62 = call i64 @waitpid(i64 %61, i32* %7, i32 0)
%63 = load i64, i64* %5
%64 = icmp eq i64 %62, %63
%65 = zext i1 %64 to i32
%66 = call i32 @assert(i32 %65)
%67 = load i32, i32* %7
%68 = icmp eq i32 %67, 0
%69 = zext i1 %68 to i32
%70 = call i32 @assert(i32 %69)
%71 = call i64 @close(i32 1)
%72 = icmp eq i64 %71, 0
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
br label %101
75: ; preds = %0
%76 = call i64 @close(i32 0)
%77 = icmp eq i64 %76, 0
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i32, i32* @PF_INET
%81 = load i32, i32* @SOCK_STREAM
%82 = call i64 @socket(i32 %80, i32 %81, i32 0)
%83 = icmp eq i64 %82, 0
%84 = zext i1 %83 to i32
%85 = call i32 @assert(i32 %84)
%86 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%87 = load i32, i32* %4
%88 = call i64 @connect(i32 0, %struct.sockaddr* %86, i32 %87)
%89 = icmp eq i64 %88, 0
%90 = zext i1 %89 to i32
%91 = call i32 @assert(i32 %90)
%92 = load i32, i32* @MSG_DONTROUTE
%93 = call i32 @send(i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.data, i64 0, i64 0), i64 4, i32 %92)
%94 = icmp eq i32 %93, 4
%95 = zext i1 %94 to i32
%96 = call i32 @assert(i32 %95)
%97 = call i64 @close(i32 0)
%98 = icmp eq i64 %97, 0
%99 = zext i1 %98 to i32
%100 = call i32 @assert(i32 %99)
br label %101
101: ; preds = %75, %45
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.data = internal constant [5 x i8] c"data\00"
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@MSG_WAITALL = global i32 0
@MSG_DONTROUTE = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca i32
%3 = alloca [5 x i8]
%4 = alloca i32
%5 = bitcast %struct.sockaddr_in* %1 to i8*
%6 = bitcast i32* %2 to i8*
store i32 8, i32* %2
%7 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 8)
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_LOOPBACK
%11 = call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %11, i32* %12
%13 = call i64 @close(i32 0)
%14 = call i64 @close(i32 1)
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i64 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i64 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i64 @bind(i32 0, %struct.sockaddr* %21, i32 8)
%23 = icmp eq i64 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i64 @listen(i32 0, i32 5)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = call i32 @memset(%struct.sockaddr_in* %1, i32 0, i32 8)
%31 = call i64 @getsockname(i32 0, %struct.sockaddr* %21, i32* %2)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = call i64 (...) @fork()
%36 = lshr i64 %35, 63
%37 = trunc i64 %36 to i32
%38 = xor i32 %37, 1
%39 = call i32 @assert(i32 %38)
%40 = icmp eq i64 %35, 0
br i1 %40, label %69, label %41
41: ; preds = %0
%42 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%43 = bitcast i32* %4 to i8*
%44 = call i32 @accept(i32 0, %struct.sockaddr* %21, i32* %2)
%45 = icmp eq i32 %44, 1
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i64 @close(i32 0)
%49 = icmp eq i64 %48, 0
%50 = zext i1 %49 to i32
%51 = call i32 @assert(i32 %50)
%52 = load i32, i32* @MSG_WAITALL
%53 = call i32 @recv(i32 1, i8* %42, i32 5, i32 %52)
%54 = icmp eq i32 %53, 4
%55 = zext i1 %54 to i32
%56 = call i32 @assert(i32 %55)
%57 = call i64 @waitpid(i64 %35, i32* %4, i32 0)
%58 = icmp eq i64 %57, %35
%59 = zext i1 %58 to i32
%60 = call i32 @assert(i32 %59)
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, 0
%63 = zext i1 %62 to i32
%64 = call i32 @assert(i32 %63)
%65 = call i64 @close(i32 1)
%66 = icmp eq i64 %65, 0
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
br label %94
69: ; preds = %0
%70 = call i64 @close(i32 0)
%71 = icmp eq i64 %70, 0
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load i32, i32* @PF_INET
%75 = load i32, i32* @SOCK_STREAM
%76 = call i64 @socket(i32 %74, i32 %75, i32 0)
%77 = icmp eq i64 %76, 0
%78 = zext i1 %77 to i32
%79 = call i32 @assert(i32 %78)
%80 = load i32, i32* %2
%81 = call i64 @connect(i32 0, %struct.sockaddr* %21, i32 %80)
%82 = icmp eq i64 %81, 0
%83 = zext i1 %82 to i32
%84 = call i32 @assert(i32 %83)
%85 = load i32, i32* @MSG_DONTROUTE
%86 = call i32 @send(i32 0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @main.data, i64 0, i64 0), i64 4, i32 %85)
%87 = icmp eq i32 %86, 4
%88 = zext i1 %87 to i32
%89 = call i32 @assert(i32 %88)
%90 = call i64 @close(i32 0)
%91 = icmp eq i64 %90, 0
%92 = zext i1 %91 to i32
%93 = call i32 @assert(i32 %92)
br label %94
94: ; preds = %69, %41
ret i32 0
}