#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ srv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  if (argc == 1) {
    printf("Usage: %s <command>.\nsuch as: %s \"ls\"\n", argv[0], argv[0]);
    return 0;
  }
  struct sockaddr_in srv_addr;
  int socket_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (socket_fd < 0) {
    perror("Can not create socket");
    return 1;
  }
  char ret_buf[1024] = {0};
  int len = sizeof(srv_addr);
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_port = htons(10000);
  srv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  sendto(socket_fd, argv[1], strlen(argv[1]) + 1, 0,
         (struct sockaddr *)&srv_addr, len);
  recvfrom(socket_fd, ret_buf, 1024, 0, (struct sockaddr *)&srv_addr, &len);
  printf("%s", ret_buf);
  close(socket_fd);
  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)
cmpl   $0x1,-0x8(%rbp)
jne    11eb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12fe <main+0x15e>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1229 <main+0x89>
lea    0xe0f(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12fe <main+0x15e>
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0xc,-0x434(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xdd7(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
mov    -0x434(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    -0x24(%rbp),%edi
lea    -0x430(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x434(%rbp),%r9
call   10a0 <recvfrom@plt>
lea    -0x430(%rbp),%rsi
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jne    11d3 <main+0x33>
mov    (%rbx),%rdx
lea    0xe3f(%rip),%rdi
xor    %r15d,%r15d
mov    %rdx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1298 <main+0xf8>
mov    0x2e0e(%rip),%r12
mov    (%r12),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
xor    %r15d,%r15d
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12ab <main+0x10b>
mov    %eax,%ebp
lea    0x20(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0xc,0xc(%rsp)
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    $0x2710,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe09(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%r12
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r12,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r12,%r8
call   10a0 <recvfrom@plt>
lea    0xdc0(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r15d,%eax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd75(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%r15d
jmp    1298 <main+0xf8>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Usage: %s <command>.\0Asuch as: %s \22ls\22\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"Can not create socket\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %18)
store i32 0, i32* %3
br label %57
20: ; preds = %2
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %57
28: ; preds = %20
%29 = bitcast [1024 x i8]* %8 to i8*
store i32 12, i32* %9
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = call i32 @htons(i32 10000)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %32, i32* %33
%34 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* %7
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i64 @strlen(i8* %43)
%45 = add nsw i64 %44, 1
%46 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%47 = load i32, i32* %9
%48 = call i32 @sendto(i32 %37, i8* %40, i64 %45, i32 0, %struct.sockaddr* %46, i32 %47)
%49 = load i32, i32* %7
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%52 = call i32 @recvfrom(i32 %49, i8* %50, i32 1024, i32 0, %struct.sockaddr* %51, i32* %9)
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%54 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %7
%56 = call i32 @close(i32 %55)
store i32 0, i32* %3
br label %57
57: ; preds = %28, %26, %12
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Usage: %s <command>.\0Asuch as: %s \22ls\22\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [22 x i8] c"Can not create socket\00"
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = icmp eq i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %8)
br label %38
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %36
18: ; preds = %10
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = tail call i32 @htons(i32 10000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i64 @strlen(i8* dereferenceable(1) %28)
%30 = add nsw i64 %29, 1
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @sendto(i32 %14, i8* %28, i64 %30, i32 0, %struct.sockaddr* %31, i32 12)
%33 = call i32 @recvfrom(i32 %14, i8* %19, i32 1024, i32 0, %struct.sockaddr* %31, i32* %5)
%34 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%35 = call i32 @close(i32 %14)
br label %36
36: ; preds = %18, %16
%37 = phi i32 [ 1, %16 ], [ 0, %18 ]
br label %38
38: ; preds = %36, %7
%39 = phi i32 [ 0, %7 ], [ %37, %36 ]
ret i32 %39
}