#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int udp_socket, result;
  ssize_t received;
  struct addrinfo addr_hints;
  struct addrinfo *addr_result;
  char recv_buf[80];
  char *server_ip = "plebis.net";
  memset(&addr_hints, 0, sizeof(struct addrinfo));
  addr_hints.ai_family = AF_INET;
  addr_hints.ai_socktype = SOCK_DGRAM;
  if (argc == 2) {
    server_ip = argv[1];
  }
  result = getaddrinfo(server_ip, "7777", &addr_hints, &addr_result);
  if (result != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(result));
    return 1;
  }
  udp_socket = socket(AF_INET, SOCK_DGRAM, 0);
  if (udp_socket == -1) {
    perror("socket");
    return 1;
  }
  result = sendto(udp_socket, "", 0, 0, addr_result->ai_addr,
                  addr_result->ai_addrlen);
  if (result == -1) {
    perror("sendto");
    return 1;
  }
  received = recv(udp_socket, recv_buf, 80, 0);
  if (received == -1) {
    perror("recv");
    return 1;
  }
  recv_buf[received] = '\0';
  printf("%s", recv_buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe50(%rip),%rax
mov    %rax,-0x98(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f8 <main+0x68>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdi
lea    0xe05(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1258 <main+0xc8>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rdx
lea    0xdc9(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1ae>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1296 <main+0x106>
lea    0xd9c(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1ae>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x38(%rbp),%rax
mov    (%rax),%r9d
lea    0xd71(%rip),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12dd <main+0x14d>
lea    0xd5c(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1ae>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1318 <main+0x188>
lea    0xd28(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    133e <main+0x1ae>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2e31(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e1b(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
cmp    $0x2,%ebp
jne    11d7 <main+0x47>
mov    0x8(%rbx),%rdi
jmp    11de <main+0x4e>
lea    0xe22(%rip),%rdi
lea    0xe26(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
je     1220 <main+0x90>
mov    0x2dd1(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xe01(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%ebx
jmp    1289 <main+0xf9>
mov    (%r14),%edi
mov    (%r15),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1296 <main+0x106>
mov    %eax,%ebp
mov    0x8(%rsp),%rax
mov    (%rax),%r9d
mov    0x4(%rax),%r8d
lea    0xdd9(%rip),%rsi
mov    %ebp,%edi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
je     129f <main+0x10f>
lea    0x20(%rsp),%rsi
xor    %ebx,%ebx
mov    %ebp,%edi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
je     12a8 <main+0x118>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xdb5(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd84(%rip),%rdi
jmp    12af <main+0x11f>
lea    0xd82(%rip),%rdi
jmp    12af <main+0x11f>
lea    0xd80(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%ebx
jmp    1289 <main+0xf9>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32 }
@.str = [11 x i8] c"plebis.net\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [5 x i8] c"7777\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [7 x i8] c"sendto\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.addrinfo
%10 = alloca %struct.addrinfo*
%11 = alloca [80 x i8]
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %12
%13 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 16)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 3
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_DGRAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %12
br label %24
24: ; preds = %20, %2
%25 = load i8*, i8** %12
%26 = call i32 @getaddrinfo(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %9, %struct.addrinfo** %10)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = load i32, i32* %7
%32 = call i8* @gai_strerror(i32 %31)
%33 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %32)
store i32 1, i32* %3
br label %69
34: ; preds = %24
%35 = load i32, i32* @AF_INET
%36 = load i32, i32* @SOCK_DGRAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %69
42: ; preds = %34
%43 = load i32, i32* %6
%44 = load %struct.addrinfo*, %struct.addrinfo** %10
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %10
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @sendto(i32 %43, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0, i32 %46, i32 %49)
store i32 %50, i32* %7
%51 = load i32, i32* %7
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %42
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %69
55: ; preds = %42
%56 = load i32, i32* %6
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%58 = call i32 @recv(i32 %56, i8* %57, i32 80, i32 0)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %69
63: ; preds = %55
%64 = load i32, i32* %8
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 %65
store i8 0, i8* %66
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%68 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %63, %61, %53, %40, %29
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32 }
@.str = [11 x i8] c"plebis.net\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [5 x i8] c"7777\00"
@stderr = global i32 0
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [7 x i8] c"sendto\00"
@.str.6 = [5 x i8] c"recv\00"
@.str.7 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [80 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 16)
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %10, i32* %11
%12 = load i32, i32* @SOCK_DGRAM
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %12, i32* %13
%14 = icmp eq i32 %0, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
br label %18
18: ; preds = %15, %2
%19 = phi i8* [ %17, %15 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), %2 ]
%20 = call i32 @getaddrinfo(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i8* @gai_strerror(i32 %20)
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %52
26: ; preds = %18
%27 = load i32, i32* @AF_INET
%28 = load i32, i32* @SOCK_DGRAM
%29 = call i32 @socket(i32 %27, i32 %28, i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %52
33: ; preds = %26
%34 = load %struct.addrinfo*, %struct.addrinfo** %4
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @sendto(i32 %29, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0, i32 %36, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %52
43: ; preds = %33
%44 = call i32 @recv(i32 %29, i8* %8, i32 80, i32 0)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %52
48: ; preds = %43
%49 = sext i32 %44 to i64
%50 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %49
store i8 0, i8* %50
%51 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %8)
br label %52
52: ; preds = %48, %46, %41, %31, %22
%53 = phi i32 [ 1, %22 ], [ 1, %31 ], [ 1, %41 ], [ 1, %46 ], [ 0, %48 ]
ret i32 %53
}