#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 create_inet_dgram_socket(int, int /*<<< orphan*/);
int destroy_inet_socket(int);
int /*<<< orphan*/ exit(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);
int sendto_inet_dgram_socket(int, char *, int, char *, char *,
                             int /*<<< orphan*/);
int write(int, char *, int);
int main(void) {
  int sfd;
  char buf[16];
  int ret;
  sfd = create_inet_dgram_socket(3, 0);
  if (sfd < 0) {
    perror(0);
    exit(1);
  }
  ret = sendto_inet_dgram_socket(sfd, "abcde", 5, "localhost", "1234", 0);
  if (ret < 0) {
    perror(0);
    exit(1);
  }
  ret = recvfrom_inet_dgram_socket(sfd, buf, 5, 0, 0, 0, 0, 0, 1);
  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)
mov    $0x3,%edi
xor    %esi,%esi
call   1090 <create_inet_dgram_socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a9 <main+0x39>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    0xe4d(%rip),%rsi
mov    $0x5,%edx
lea    0xe47(%rip),%rcx
lea    0xe4a(%rip),%r8
xor    %r9d,%r9d
call   1070 <sendto_inet_dgram_socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ec <main+0x7c>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x5,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x1,0x10(%rsp)
call   1050 <recvfrom_inet_dgram_socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    123b <main+0xcb>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    126c <main+0xfc>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <destroy_inet_socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1292 <main+0x122>
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    $0x3,%edi
xor    %esi,%esi
call   1090 <create_inet_dgram_socket@plt>
test   %eax,%eax
js     1203 <main+0x93>
mov    %eax,%ebx
lea    0xe72(%rip),%rsi
lea    0xe71(%rip),%rcx
lea    0xe74(%rip),%r8
mov    %eax,%edi
mov    $0x5,%edx
xor    %r9d,%r9d
call   1070 <sendto_inet_dgram_socket@plt>
test   %eax,%eax
js     1203 <main+0x93>
sub    $0x8,%rsp
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   $0x1
push   $0x0
push   $0x0
call   1050 <recvfrom_inet_dgram_socket@plt>
add    $0x20,%rsp
test   %eax,%eax
js     1203 <main+0x93>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    $0x5,%edx
call   1030 <write@plt>
test   %eax,%eax
js     1203 <main+0x93>
mov    %ebx,%edi
call   1040 <destroy_inet_socket@plt>
test   %eax,%eax
js     1203 <main+0x93>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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