#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 */
typedef int /*<<< orphan*/ their_addr;
struct in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(struct in_addr);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
             struct sockaddr *, int *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd, numbytes, addr_len;
  struct hostent *he;
  struct sockaddr_in their_addr;
  if (argc != 3) {
    fprintf(stderr, "usage: talker hostname message\n");
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    perror("Talker gethostbyname");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("Talker socket");
    exit(1);
  }
  memset(&their_addr, 0, sizeof(their_addr));
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(4950);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  if ((numbytes = sendto(sockfd, argv[2], strlen(argv[2]), 0,
                         (struct sockaddr *)&their_addr,
                         sizeof(struct sockaddr))) == -1) {
    perror("Talker sendto");
    exit(1);
  }
  printf("Sent %d bytes to %s\n", numbytes, inet_ntoa(their_addr.sin_addr));
  addr_len = sizeof(struct sockaddr);
  if ((numbytes = recvfrom(sockfd, argv[2], strlen(argv[2]), 0,
                           (struct sockaddr *)&their_addr, &addr_len)) == -1) {
    perror("recvfrom fail");
    exit(1);
  }
  printf("Echo: %s\n", argv[2]);
  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   $0x3,-0x8(%rbp)
je     120f <main+0x3f>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1240 <main+0x70>
lea    0xdef(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
mov    0x2d90(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    127b <main+0xab>
lea    0xdc9(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x1356,%edi
call   1050 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    130b <main+0x13b>
lea    0xd47(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x38(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    -0x58(%rbp),%esi
mov    %rax,%rdx
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x4,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    138d <main+0x1bd>
lea    0xce8(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    12f3 <main+0x123>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     1312 <main+0x142>
mov    %rax,%rbx
mov    0x2de4(%rip),%r12
mov    (%r12),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     131b <main+0x14b>
mov    %eax,%ebp
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    $0x1356,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0x4,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     1324 <main+0x154>
mov    %eax,%ebx
mov    (%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xdc1(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
movl   $0x4,0xc(%rsp)
mov    0x10(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10c0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     132d <main+0x15d>
mov    0x10(%r14),%rsi
lea    0xd9e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xcfd(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd07(%rip),%rdi
jmp    1334 <main+0x164>
lea    0xd13(%rip),%rdi
jmp    1334 <main+0x164>
lea    0xd18(%rip),%rdi
jmp    1334 <main+0x164>
lea    0xd32(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

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

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