#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_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
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 *, int, char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  struct addrinfo hints, *servinfo, *p;
  int rv;
  int numbytes;
  if (argc != 2) {
    fprintf(stderr, "usage: %s hostname\n", argv[0]);
    exit(1);
  }
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_DGRAM;
  if ((rv = getaddrinfo(argv[1], "4950", &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
    return 1;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      perror("socket");
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "talker: failed to create socket\n");
    return 2;
  }
  if ((numbytes = sendto(sockfd, "hello world", strlen("hello world"), 0,
                         p->ai_addr, p->ai_addrlen)) == -1) {
    perror("sendto");
    exit(1);
  }
  freeaddrinfo(servinfo);
  printf("sent %d bytes to %s\n", numbytes, argv[1]);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1208 <main+0x48>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd5(%rip),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
je     128c <main+0xcc>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x4c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    139f <main+0x1df>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     12ec <main+0x12c>
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x48(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12d6 <main+0x116>
lea    0xd5e(%rip),%rdi
call   10a0 <perror@plt>
jmp    12db <main+0x11b>
jmp    12ec <main+0x12c>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    1294 <main+0xd4>
cmpq   $0x0,-0x48(%rbp)
jne    131a <main+0x15a>
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    139f <main+0x1df>
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    0xd2b(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x58(%rbp),%edi
mov    %eax,%edx
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%r8d
mov    -0x48(%rbp),%rax
mov    (%rax),%r9d
lea    0xd0b(%rip),%rsi
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x50(%rbp)
cmp    $0xffffffff,%eax
jne    1370 <main+0x1b0>
lea    0xcfd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    -0x50(%rbp),%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xcda(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12fd <main+0x13d>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
lea    0xe05(%rip),%rsi
mov    %rsp,%rcx
mov    %rbx,%rdx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     124b <main+0x8b>
mov    0x2dab(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xde4(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%ebx
jmp    12f0 <main+0x130>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     127f <main+0xbf>
lea    0xdcf(%rip),%r15
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
jne    129d <main+0xdd>
mov    %r15,%rdi
call   10a0 <perror@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    125b <main+0x9b>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x2,%ebx
jmp    12f0 <main+0x130>
mov    %eax,%ebp
lea    0xdac(%rip),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    (%rbx),%r9d
mov    0x4(%rbx),%r8d
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
je     1321 <main+0x161>
mov    %eax,%r15d
mov    (%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    0x8(%r14),%rdx
lea    0xd84(%rip),%rdi
mov    %r15d,%esi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xcf0(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xd36(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [5 x i8] c"4950\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [33 x i8] c"talker: failed to create socket\0A\00"
@.str.5 = [12 x i8] c"hello world\00"
@.str.6 = [7 x i8] c"sendto\00"
@.str.7 = [21 x i8] c"sent %d bytes to %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i32 @memset(%struct.addrinfo* %7, i32 0, i32 32)
%23 = load i32, i32* @AF_UNSPEC
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_DGRAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %25, i32* %26
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @getaddrinfo(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %7, %struct.addrinfo** %8)
store i32 %30, i32* %10
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i32, i32* %10
%35 = call i8* @gai_strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %91
37: ; preds = %21
%38 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %38, %struct.addrinfo** %9
br label %39
39: ; preds = %57, %37
%40 = load %struct.addrinfo*, %struct.addrinfo** %9
%41 = icmp ne %struct.addrinfo* %40, null
br i1 %41, label %42, label %61
42: ; preds = %39
%43 = load %struct.addrinfo*, %struct.addrinfo** %9
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i32 0, i32 4
%45 = load i32, i32* %44
%46 = load %struct.addrinfo*, %struct.addrinfo** %9
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 3
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %9
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = call i32 @socket(i32 %45, i32 %48, i32 %51)
store i32 %52, i32* %6
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %56
54: ; preds = %42
%55 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %57
56: ; preds = %42
br label %61
57: ; preds = %54
%58 = load %struct.addrinfo*, %struct.addrinfo** %9
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 5
%60 = load %struct.addrinfo*, %struct.addrinfo** %59
store %struct.addrinfo* %60, %struct.addrinfo** %9
br label %39
61: ; preds = %56, %39
%62 = load %struct.addrinfo*, %struct.addrinfo** %9
%63 = icmp eq %struct.addrinfo* %62, null
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %3
br label %91
67: ; preds = %61
%68 = load i32, i32* %6
%69 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%70 = load %struct.addrinfo*, %struct.addrinfo** %9
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %70, i32 0, i32 1
%72 = load i32, i32* %71
%73 = load %struct.addrinfo*, %struct.addrinfo** %9
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i32 @sendto(i32 %68, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %69, i32 0, i32 %72, i32 %75)
store i32 %76, i32* %11
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %67
%79 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %67
%82 = load %struct.addrinfo*, %struct.addrinfo** %8
%83 = call i32 @freeaddrinfo(%struct.addrinfo* %82)
%84 = load i32, i32* %11
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %84, i8* %87)
%89 = load i32, i32* %6
%90 = call i32 @close(i32 %89)
store i32 0, i32* %3
br label %91
91: ; preds = %81, %64, %32
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@stderr = global i32 0
@.str = [20 x i8] c"usage: %s hostname\0A\00"
@AF_UNSPEC = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [5 x i8] c"4950\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [33 x i8] c"talker: failed to create socket\0A\00"
@.str.5 = [12 x i8] c"hello world\00"
@.str.6 = [7 x i8] c"sendto\00"
@.str.7 = [21 x i8] c"sent %d bytes to %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_DGRAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @getaddrinfo(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %3, %struct.addrinfo** %4)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = load %struct.addrinfo*, %struct.addrinfo** %4
%25 = icmp eq %struct.addrinfo* %24, null
br i1 %25, label %45, label %30
26: ; preds = %13
%27 = load i32, i32* @stderr
%28 = call i8* @gai_strerror(i32 %21)
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %65
30: ; preds = %23, %40
%31 = phi %struct.addrinfo* [ %43, %40 ], [ %24, %23 ]
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 4
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 3
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 2
%37 = load i32, i32* %36
%38 = call i32 @socket(i32 %33, i32 %35, i32 %37)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %48
40: ; preds = %30
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 5
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %30
45: ; preds = %40, %23
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
br label %65
48: ; preds = %30
%49 = call i32 @strlen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i64 0, i32 0
%53 = load i32, i32* %52
%54 = call i32 @sendto(i32 %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %49, i32 0, i32 %51, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %48
%60 = load %struct.addrinfo*, %struct.addrinfo** %4
%61 = call i32 @freeaddrinfo(%struct.addrinfo* %60)
%62 = load i8*, i8** %19
%63 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %54, i8* %62)
%64 = call i32 @close(i32 %38)
br label %65
65: ; preds = %59, %45, %26
%66 = phi i32 [ 1, %26 ], [ 2, %45 ], [ 0, %59 ]
ret i32 %66
}