#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ cli_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ 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 sock;
  char buf[1024];
  int msg_len;
  socklen_t cli_len;
  struct sockaddr_in cli_addr, serv_addr;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <host> <port> <msg>\n", argv[0]);
    exit(1);
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock == -1) {
    perror("socket() failed");
    exit(1);
  };
  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
  serv_addr.sin_port = htons(atoi(argv[2]));
  sendto(sock, argv[3], strlen(argv[3]), 0, (struct sockaddr *)&serv_addr,
         sizeof(serv_addr));
  cli_len = sizeof(cli_addr);
  msg_len =
      recvfrom(sock, buf, 1024, 0, (struct sockaddr *)&cli_addr, &cli_len);
  buf[msg_len] = '\0';
  printf("recv from server: %s", buf);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1219 <main+0x49>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    0x2db7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1255 <main+0x85>
lea    0xdd9(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x448(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x444(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x448(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x454(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x450(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    %eax,%edx
lea    -0x448(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
movl   $0xc,-0x428(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
lea    -0x438(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x428(%rbp),%r9
call   10b0 <recvfrom@plt>
mov    %eax,-0x424(%rbp)
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xcf2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r14
cmp    $0x4,%edi
jne    12c0 <main+0xf0>
mov    0x2df8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12e2 <main+0x112>
mov    %eax,%ebp
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r14),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%r14),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x18(%r14),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rbx
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xd8e(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd2d(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd36(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s <host> <port> <msg>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [21 x i8] c"recv from server: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_DGRAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = call i32 @memset(%struct.sockaddr_in* %11, i32 0, i32 12)
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 2
store i32 %32, i32* %33
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @inet_addr(i8* %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i32 %37, i32* %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %11, i32 0, i32 0
store i32 %44, i32* %45
%46 = load i32, i32* %6
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 3
%49 = load i8*, i8** %48
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i32 @strlen(i8* %52)
%54 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%55 = call i32 @sendto(i32 %46, i8* %49, i32 %53, i32 0, %struct.sockaddr* %54, i32 12)
store i32 12, i32* %9
%56 = load i32, i32* %6
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%58 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%59 = call i32 @recvfrom(i32 %56, i8* %57, i32 1024, i32 0, %struct.sockaddr* %58, i32* %9)
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %61
store i8 0, i8* %62
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %63)
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"Usage: %s <host> <port> <msg>\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [21 x i8] c"recv from server: %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp eq i32 %0, 4
br i1 %11, label %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = tail call i32 @socket(i32 %18, i32 %19, i32 0)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %17
%26 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @inet_addr(i8* %30)
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i32 %31, i32* %32
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %36, i32* %37
%38 = getelementptr inbounds i8*, i8** %1, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%42 = call i32 @sendto(i32 %20, i8* %39, i32 %40, i32 0, %struct.sockaddr* %41, i32 12)
store i32 12, i32* %4
%43 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%44 = call i32 @recvfrom(i32 %20, i8* %7, i32 1024, i32 0, %struct.sockaddr* %43, i32* %4)
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %45
store i8 0, i8* %46
%47 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%48 = call i32 @close(i32 %20)
ret i32 0
}