#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, 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*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, n;
  socklen_t serverlen;
  struct sockaddr_in serveraddr;
  struct hostent *server;
  char buf[1024];
  const char hostname[] = "127.0.0.1";
  int portno = 5000;
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    error("ERROR opening socket");
  }
  server = gethostbyname(hostname);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host as %s\n", hostname);
    exit(0);
  }
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr,
        server->h_length);
  serveraddr.sin_port = htons(portno);
  bzero(buf, 1024);
  strcpy(buf, "00000200FFFF");
  serverlen = sizeof(serveraddr);
  printf("Send to server: %s\n", buf);
  n = sendto(sockfd, buf, strlen(buf), 0, (struct sockaddr *)&serveraddr,
             serverlen);
  if (n < 0)
    error("ERROR in sendto");
  n = recvfrom(sockfd, buf, sizeof(buf), 0, (struct sockaddr *)&serveraddr,
               &serverlen);
  if (n < 0)
    error("ERROR in recvfrom");
  printf("Response from server: %s\n", buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe10(%rip),%rax
mov    %rax,-0x43a(%rbp)
mov    0xe0a(%rip),%ax
mov    %ax,-0x432(%rbp)
movl   $0x1388,-0x440(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dc1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1241 <main+0x71>
lea    0xdce(%rip),%rdi
call   10c0 <error@plt>
lea    -0x43a(%rbp),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    127f <main+0xaf>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    -0x43a(%rbp),%rdx
lea    0xdac(%rip),%rsi
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bcopy@plt>
mov    -0x440(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    -0x430(%rbp),%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    -0x430(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0xc,-0x1c(%rbp)
lea    -0x430(%rbp),%rsi
lea    0xd4c(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
mov    -0x1c(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    135a <main+0x18a>
lea    0xd06(%rip),%rdi
call   10c0 <error@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x28(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x1c(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1391 <main+0x1c1>
lea    0xcdf(%rip),%rdi
call   10c0 <error@plt>
lea    -0x430(%rbp),%rsi
lea    0xcde(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x438,%rsp
movabs $0x2e302e302e373231,%rax
2e 30 2e
mov    %rax,0x20(%rsp)
movw   $0x31,0x28(%rsp)
mov    0x2dee(%rip),%r15
mov    (%r15),%edi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    121f <main+0x4f>
lea    0xdf0(%rip),%rdi
call   10c0 <error@plt>
lea    0x20(%rsp),%rdi
call   1080 <gethostbyname@plt>
test   %rax,%rax
je     1321 <main+0x151>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdi
mov    (%rbx),%edx
call   10b0 <memmove@plt>
mov    $0x1388,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   10d0 <bzero@plt>
lea    0xdb5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
movl   $0xc,0xc(%rsp)
lea    0xdab(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
jns    12d3 <main+0x103>
lea    0xd8d(%rip),%rdi
call   10c0 <error@plt>
lea    0x30(%rsp),%rsi
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10a0 <recvfrom@plt>
test   %eax,%eax
jns    1300 <main+0x130>
lea    0xd70(%rip),%rdi
call   10c0 <error@plt>
lea    0xd76(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
lea    0xcee(%rip),%rsi
lea    0x20(%rsp),%rdx
call   1090 <fprintf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@__const.main.hostname = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str = [21 x i8] c"ERROR opening socket\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"ERROR, no such host as %s\0A\00"
@.str.2 = [13 x i8] c"00000200FFFF\00"
@.str.3 = [20 x i8] c"Send to server: %s\0A\00"
@.str.4 = [16 x i8] c"ERROR in sendto\00"
@.str.5 = [18 x i8] c"ERROR in recvfrom\00"
@.str.6 = [26 x i8] c"Response from server: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [1024 x i8]
%6 = alloca [10 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %2
%18 = call %struct.hostent* @gethostbyname(i8* %10)
%19 = icmp eq %struct.hostent* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %17
%25 = call i32 @bzero(i8* %8, i32 12)
%26 = load i32, i32* @AF_INET
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i64 0, i32 1
%29 = load i64, i64* %28
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%32 = bitcast i32* %31 to i8*
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @htons(i32 5000)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %35, i32* %36
%37 = call i32 @bzero(i8* %9, i32 1024)
%38 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 12, i32* %3
%39 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%40 = call i32 @strlen(i8* %9)
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = call i32 @sendto(i32 %13, i8* %9, i32 %40, i32 0, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %24
%45 = call i32 @error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %44, %24
%47 = call i32 @recvfrom(i32 %13, i8* %9, i32 1024, i32 0, %struct.sockaddr* %41, i32* %3)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
%52 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i8* %9)
ret i32 0
}