#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 connect_inet_dgram_socket(int, char *, char *);
int create_inet_dgram_socket(int, int /*<<< orphan*/);
int destroy_inet_socket(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int recvfrom_inet_dgram_socket(int, char *, int, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int write(int, char *, int);
int main(void) {
  int sfd, ret;
  char buf[16];
  memset(buf, 0, 16);
  ret = sfd = create_inet_dgram_socket(3, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = connect_inet_dgram_socket(sfd, "localhost", "1234");
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = write(sfd, "abcde", 5);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  sleep(2);
  ret = recvfrom_inet_dgram_socket(sfd, buf, 16, 0, 0, 0, 0, 0, 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = write(1, buf, 5);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = destroy_inet_socket(sfd);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    $0x3,%edi
xor    %esi,%esi
call   10a0 <create_inet_dgram_socket@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11dc <main+0x4c>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe1a(%rip),%rsi
lea    0xe1d(%rip),%rdx
call   1080 <connect_inet_dgram_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1210 <main+0x80>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xdf5(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1242 <main+0xb2>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x2,%edi
call   10b0 <sleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x10(%rsp)
call   1060 <recvfrom_inet_dgram_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    129b <main+0x10b>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x20(%rbp),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12cc <main+0x13c>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <destroy_inet_socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12f2 <main+0x162>
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    $0x3,%edi
xor    %esi,%esi
call   10a0 <create_inet_dgram_socket@plt>
test   %eax,%eax
js     1248 <main+0xb8>
mov    %eax,%ebx
lea    0xe3f(%rip),%rsi
lea    0xe42(%rip),%rdx
mov    %eax,%edi
call   1080 <connect_inet_dgram_socket@plt>
test   %eax,%eax
js     1248 <main+0xb8>
lea    0xe35(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1248 <main+0xb8>
mov    $0x2,%edi
call   10b0 <sleep@plt>
sub    $0x8,%rsp
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x0
push   $0x0
push   $0x0
call   1060 <recvfrom_inet_dgram_socket@plt>
add    $0x20,%rsp
test   %eax,%eax
js     1248 <main+0xb8>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1248 <main+0xb8>
mov    %ebx,%edi
call   1040 <destroy_inet_socket@plt>
test   %eax,%eax
js     1248 <main+0xb8>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"1234\00"
@.str.2 = [6 x i8] c"abcde\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [16 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 16)
%7 = call i32 @create_inet_dgram_socket(i32 3, i32 0)
store i32 %7, i32* %2
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i32 0)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %2
%15 = call i32 @connect_inet_dgram_socket(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = call i32 @perror(i32 0)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i32, i32* %2
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i32 0)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = call i32 @sleep(i32 2)
%31 = load i32, i32* %2
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%33 = call i32 @recvfrom_inet_dgram_socket(i32 %31, i8* %32, i32 16, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
store i32 %33, i32* %3
%34 = load i32, i32* %3
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = call i32 @perror(i32 0)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%41 = call i32 @write(i32 1, i8* %40, i32 5)
store i32 %41, i32* %3
%42 = load i32, i32* %3
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = call i32 @perror(i32 0)
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %39
%48 = load i32, i32* %2
%49 = call i32 @destroy_inet_socket(i32 %48)
store i32 %49, i32* %3
%50 = load i32, i32* %3
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = call i32 @perror(i32 0)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"localhost\00"
@.str.1 = [5 x i8] c"1234\00"
@.str.2 = [6 x i8] c"abcde\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i32 16)
%4 = call i32 @create_inet_dgram_socket(i32 3, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i32 0)
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @connect_inet_dgram_socket(i32 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @perror(i32 0)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = call i32 @write(i32 %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i32 0)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @sleep(i32 2)
%23 = call i32 @recvfrom_inet_dgram_socket(i32 %4, i8* %2, i32 16, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0)
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = call i32 @perror(i32 0)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i32 @write(i32 1, i8* %2, i32 5)
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @perror(i32 0)
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %28
%35 = call i32 @destroy_inet_socket(i32 %4)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = call i32 @perror(i32 0)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %34
ret i32 0
}