#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 {
  int /*<<< orphan*/ sin_zero;
  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*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sockfd, numbytes, sin_size;
  char buf[100] = "Hello, world!";
  struct hostent *he;
  struct sockaddr_in their_addr;
  if (argc != 2) {
    fprintf(stderr, " usage: client hostname\n ");
    exit(1);
  }
  if ((he = gethostbyname(argv[1])) == NULL) {
    herror(" gethostbyname ");
    exit(1);
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  their_addr.sin_family = AF_INET;
  their_addr.sin_port = htons(3490);
  their_addr.sin_addr = *((struct in_addr *)he->h_addr);
  bzero(&(their_addr.sin_zero), 8);
  numbytes = sendto(sockfd, buf, 100, 0, (struct sockaddr *)&their_addr,
                    sizeof(their_addr));
  if (numbytes == -1) {
    perror("sendto");
    exit(1);
  }
  printf("Send: %s", buf);
  numbytes =
      recvfrom(sockfd, buf, 100, 0, (struct sockaddr *)&their_addr, &sin_size);
  if (numbytes == -1) {
    perror("recvfrom");
    exit(1);
  }
  buf[numbytes] = '\0';
  printf("Received: %s ", buf);
  close(sockfd);
  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    -0x80(%rbp),%rdi
lea    0xe0c(%rip),%rsi
mov    $0x64,%edx
call   1090 <memcpy@plt>
cmpl   $0x2,-0x8(%rbp)
je     1227 <main+0x57>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <gethostbyname@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    125b <main+0x8b>
lea    0xe32(%rip),%rdi
call   10a0 <herror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1296 <main+0xc6>
lea    0xe07(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    $0xda2,%edi
call   1030 <htons@plt>
mov    %eax,-0x90(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
lea    -0x98(%rbp),%rdi
mov    $0x8,%esi
call   10d0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x98(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1050 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    131b <main+0x14b>
lea    0xd89(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x80(%rbp),%rsi
lea    0xd76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x98(%rbp),%r8
mov    $0x64,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    136c <main+0x19c>
lea    0xd48(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xd2e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
movaps 0xe7e(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe62(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xe46(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xe2a(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xe0e(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xdf2(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x80(%rsp)
cmp    $0x2,%edi
jne    1317 <main+0x157>
mov    0x8(%rsi),%rdi
call   1070 <gethostbyname@plt>
test   %rax,%rax
je     1336 <main+0x176>
mov    %rax,%rbx
mov    0x2da5(%rip),%r14
mov    (%r14),%edi
mov    0x2d93(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     134c <main+0x18c>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0x14(%rsp)
mov    $0xda2,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   10c0 <bzero@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    $0x10,%r9d
call   1050 <sendto@plt>
cmp    $0xffffffff,%eax
je     1355 <main+0x195>
lea    0xddf(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0x8(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     135e <main+0x19e>
cltq
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xdb6(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd3d(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd41(%rip),%rdi
call   1090 <herror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    0xd3b(%rip),%rdi
jmp    1365 <main+0x1a5>
lea    0xd39(%rip),%rdi
jmp    1365 <main+0x1a5>
lea    0xd40(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

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

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