#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ 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*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in sa;
  int bytes_sent;
  char buffer[200];
  strcpy(buffer, "hello world!");
  sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if (-1 == sock) {
    printf("Error Creating Socket");
    exit(EXIT_FAILURE);
  }
  memset(&sa, 0, sizeof sa);
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = inet_addr("127.0.0.1");
  sa.sin_port = htons(7654);
  bytes_sent = sendto(sock, buffer, strlen(buffer), 0, (struct sockaddr *)&sa,
                      sizeof sa);
  if (bytes_sent < 0) {
    printf("Error sending packet: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  int temp;
  recvfrom(sock, buffer, strlen(buffer), 0, (struct sockaddr *)&sa, &temp);
  printf("Answer: %s\n", buffer);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xf0(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    0x2dab(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    1239 <main+0x79>
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xdc7(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1de6,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x104(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x100(%rbp)
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x104(%rbp),%edi
mov    -0x100(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12ee <main+0x12e>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0xf0(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rsi
mov    %eax,%edx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
lea    -0xf4(%rbp),%r9
call   10b0 <recvfrom@plt>
lea    -0xf0(%rbp),%rsi
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xe2d(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12b6 <main+0xf6>
mov    %eax,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xdf5(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1de6,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
js     12c6 <main+0x106>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
lea    0xdb1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd50(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12e5 <main+0x125>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd52(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"hello world!\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [22 x i8] c"Error Creating Socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [26 x i8] c"Error sending packet: %s\0A\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"Answer: %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.sockaddr_in
%8 = alloca i32
%9 = alloca [200 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = load i32, i32* @IPPROTO_UDP
%16 = call i32 @socket(i32 %13, i32 %14, i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 -1, %17
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = call i32 @memset(%struct.sockaddr_in* %7, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = call i32 @htons(i32 7654)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %6
%33 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%34 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%37 = call i32 @sendto(i32 %32, i8* %33, i32 %35, i32 0, %struct.sockaddr* %36, i32 12)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %23
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %23
%47 = load i32, i32* %6
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%49 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%50 = call i32 @strlen(i8* %49)
%51 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%52 = call i32 @recvfrom(i32 %47, i8* %48, i32 %50, i32 0, %struct.sockaddr* %51, i32* %10)
%53 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %6
%56 = call i32 @close(i32 %55)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"hello world!\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@.str.1 = [22 x i8] c"Error Creating Socket\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [26 x i8] c"Error sending packet: %s\0A\00"
@errno = global i32 0
@.str.4 = [12 x i8] c"Answer: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [200 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%8 = call i32 @strcpy(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @PF_INET
%10 = load i32, i32* @SOCK_DGRAM
%11 = load i32, i32* @IPPROTO_UDP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = call i32 @htons(i32 7654)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = call i32 @strlen(i8* %7)
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @sendto(i32 %12, i8* %7, i32 %26, i32 0, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %18
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %18
%37 = bitcast i32* %5 to i8*
%38 = call i32 @strlen(i8* %7)
%39 = call i32 @recvfrom(i32 %12, i8* %7, i32 %38, i32 0, %struct.sockaddr* %27, i32* %5)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %7)
%41 = call i32 @close(i32 %12)
ret i32 0
}