#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_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 *, ...);
scalar_t__ rand();
char *randstring(long);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  struct addrinfo hints, *servinfo, *p;
  int rv;
  long limit = 512;
  while (1) {
    int numbytes = (int)rand();
    if (numbytes < 512) {
      break;
    }
  }
  char *random_string = randstring(limit);
  if (argc != 2) {
    fprintf(stderr, "usage: talker hostname message\n");
    exit(1);
  }
  while (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("talker: socket");
        continue;
      }
      break;
    }
    if (p == NULL) {
      fprintf(stderr, "talker: failed to bind socket\n");
      return 2;
    }
    freeaddrinfo(servinfo);
    printf("talker: sent %d bytes to %s\n", strlen(random_string), argv[1]);
    printf("The string contained: %s \n", random_string);
    close(sockfd);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x200,-0x50(%rbp)
mov    $0x0,%al
call   10d0 <rand@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x200,-0x54(%rbp)
jge    120a <main+0x3a>
jmp    120f <main+0x3f>
jmp    11ee <main+0x1e>
mov    -0x50(%rbp),%rdi
call   10b0 <randstring@plt>
mov    %rax,-0x60(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1247 <main+0x77>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    124c <main+0x7c>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd9d(%rip),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
je     12d0 <main+0x100>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x44(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xd68(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a6 <main+0x1d6>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     132f <main+0x15f>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1319 <main+0x149>
lea    0xd27(%rip),%rdi
call   1090 <perror@plt>
jmp    131e <main+0x14e>
jmp    132f <main+0x15f>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    12d8 <main+0x108>
cmpq   $0x0,-0x40(%rbp)
jne    135d <main+0x18d>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    13a6 <main+0x1d6>
mov    -0x38(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0x60(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x60(%rbp),%rsi
lea    0xcef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
jmp    124c <main+0x7c>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   10d0 <rand@plt>
cmp    $0x1ff,%eax
jg     11f0 <main+0x20>
mov    $0x200,%edi
call   10b0 <randstring@plt>
mov    %rax,0x8(%rsp)
cmp    $0x2,%ebp
jne    136f <main+0x19f>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2db7(%rip),%r15
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x2da1(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
lea    0xdcf(%rip),%rsi
mov    %rsp,%rcx
mov    %r12,%rdx
jmp    12d9 <main+0x109>
nopl   0x0(%rax)
mov    %eax,%r12d
mov    (%rsp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    0x8(%r14),%rdx
lea    0xde0(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xded(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
call   1070 <close@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x14(%rsp)
mov    0x8(%r14),%rdi
lea    0xd4d(%rip),%rsi
mov    %rbx,%rdx
mov    %rsp,%rcx
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
jne    1338 <main+0x168>
mov    (%rsp),%r13
test   %r13,%r13
je     131a <main+0x14a>
mov    0x8(%r13),%edi
mov    0x0(%r13),%edx
mov    0x4(%r13),%esi
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1260 <main+0x90>
lea    0xd2a(%rip),%rdi
call   1090 <perror@plt>
mov    0x10(%r13),%r13
test   %r13,%r13
jne    12eb <main+0x11b>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    0xd1b(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%eax
jmp    1360 <main+0x190>
mov    0x2c91(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xcd6(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c5a(%rip),%rax
mov    (%rax),%edi
lea    0xc81(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

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