#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sin;
typedef int /*<<< orphan*/ cin;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(int, char *, scalar_t__, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in sin;
  struct sockaddr_in cin;
  int port = 8000;
  socklen_t addr_len;
  int s_fd;
  char *str = "test";
  char buf[80];
  char add_p[INET_ADDRSTRLEN];
  int n;
  if (argc != 2) {
    printf("wrong command\n");
    exit(1);
  }
  str = argv[1];
  bzero(&sin, sizeof(sin));
  sin.sin_family = AF_INET;
  inet_pton(AF_INET, "127.0.0.1", &sin.sin_addr);
  sin.sin_port = htons(port);
  s_fd = socket(AF_INET, SOCK_DGRAM, 0);
  if (s_fd == -1) {
    perror("fail to create socket");
    exit(1);
  }
  sprintf(buf, "%s\0", str);
  n = sendto(s_fd, buf, strlen(str) + 1, 0, (struct sockaddr *)&sin,
             sizeof(sin));
  if (n == -1) {
    perror("fail to send\n");
    exit(1);
  }
  addr_len = sizeof(cin);
  n = recvfrom(s_fd, buf, 80, 0, (struct sockaddr *)&cin, &addr_len);
  if (n == -1) {
    perror("fail to receive\n");
    exit(1);
  } else
    printf("recive from server: %s\n", buf);
  if (close(s_fd) == -1) {
    perror("fail to close.\n");
    exit(1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1f40,-0x34(%rbp)
lea    0xe19(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rax,-0xb0(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1227 <main+0x67>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
lea    0xdaf(%rip),%rsi
call   1080 <inet_pton@plt>
mov    -0x34(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    12b1 <main+0xf1>
lea    0xd7c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x48(%rbp),%rdx
lea    0xdb8(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0xc4(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0xffffffff,-0xb4(%rbp)
jne    1336 <main+0x176>
lea    0xd0d(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0xc,-0x38(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0x30(%rbp),%r8
mov    $0x50,%edx
xor    %ecx,%ecx
lea    -0x38(%rbp),%r9
call   1090 <recvfrom@plt>
mov    %eax,-0xb4(%rbp)
cmpl   $0xffffffff,-0xb4(%rbp)
jne    1384 <main+0x1c4>
lea    0xccd(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0xa0(%rbp),%rsi
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    13c0 <main+0x200>
lea    0xcba(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x4(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
cmp    $0x2,%edi
jne    12db <main+0x10b>
mov    %rsp,%r12
mov    0x8(%rsi),%r14
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2de4(%rip),%rbx
mov    (%rbx),%edi
mov    %edi,0x18(%rsp)
lea    0x14(%rsp),%rdx
lea    0xdea(%rip),%rsi
call   10a0 <inet_pton@plt>
mov    $0x1f40,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12f1 <main+0x121>
mov    %eax,%ebx
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
lea    0x10(%rsp),%r8
mov    %ebx,%edi
mov    %r15,%rsi
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
cmp    $0xffffffff,%eax
je     12fa <main+0x12a>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %ebx,%edi
mov    $0x50,%edx
xor    %ecx,%ecx
call   10b0 <recvfrom@plt>
cmp    $0xffffffff,%eax
je     1303 <main+0x133>
lea    0xd90(%rip),%rdi
lea    0x30(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
je     130c <main+0x13c>
mov    %r12,%rsp
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd85(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xd12(%rip),%rdi
jmp    1313 <main+0x143>
lea    0xd1f(%rip),%rdi
jmp    1313 <main+0x143>
lea    0xd24(%rip),%rdi
jmp    1313 <main+0x143>
lea    0xd44(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"test\00"
@INET_ADDRSTRLEN = global i32 0
@.str.1 = [15 x i8] c"wrong command\0A\00"
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [22 x i8] c"fail to create socket\00"
@.str.4 = [4 x i8] c"%s\00\00"
@.str.5 = [14 x i8] c"fail to send\0A\00"
@.str.6 = [17 x i8] c"fail to receive\0A\00"
@.str.7 = [24 x i8] c"recive from server: %s\0A\00"
@.str.8 = [16 x i8] c"fail to close.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [80 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 8000, i32* %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %11
%16 = load i32, i32* @INET_ADDRSTRLEN
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca i8, i64 %17
store i64 %17, i64* %14
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
store i8* %28, i8** %11
%29 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%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 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%34 = call i32 @inet_pton(i32 %32, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %33)
%35 = load i32, i32* %8
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* @AF_INET
%39 = load i32, i32* @SOCK_DGRAM
%40 = call i32 @socket(i32 %38, i32 %39, i32 0)
store i32 %40, i32* %10
%41 = load i32, i32* %10
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %25
%44 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %25
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%48 = load i8*, i8** %11
%49 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = load i32, i32* %10
%51 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%52 = load i8*, i8** %11
%53 = call i64 @strlen(i8* %52)
%54 = add nsw i64 %53, 1
%55 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%56 = call i32 @sendto(i32 %50, i8* %51, i64 %54, i32 0, %struct.sockaddr* %55, i32 12)
store i32 %56, i32* %15
%57 = load i32, i32* %15
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %46
%60 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %46
store i32 12, i32* %9
%63 = load i32, i32* %10
%64 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%65 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%66 = call i32 @recvfrom(i32 %63, i8* %64, i32 80, i32 0, %struct.sockaddr* %65, i32* %9)
store i32 %66, i32* %15
%67 = load i32, i32* %15
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %62
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %72
%76 = load i32, i32* %10
%77 = call i32 @close(i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %82
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %75
store i32 0, i32* %3
%83 = load i8*, i8** %13
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@INET_ADDRSTRLEN = global i32 0
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@SOCK_DGRAM = global i32 0
@.str.3 = [22 x i8] c"fail to create socket\00"
@.str.5 = [14 x i8] c"fail to send\0A\00"
@.str.6 = [17 x i8] c"fail to receive\0A\00"
@.str.7 = [24 x i8] c"recive from server: %s\0A\00"
@.str.8 = [16 x i8] c"fail to close.\0A\00"
@str = [14 x i8] c"wrong command\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%11 = tail call i8* @llvm.stacksave()
%12 = icmp eq i32 %0, 2
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @bzero(%struct.sockaddr_in* %3, 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 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%23 = call i32 @inet_pton(i32 %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %22)
%24 = call i32 @htons(i32 8000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_DGRAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %16
%31 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %16
%34 = call i8* @strcpy(i8* %10, i8* dereferenceable(1) %18)
%35 = call i64 @strlen(i8* dereferenceable(1) %18)
%36 = add nsw i64 %35, 1
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @sendto(i32 %28, i8* %10, i64 %36, i32 0, %struct.sockaddr* %37, i32 12)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %33
store i32 12, i32* %5
%44 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%45 = call i32 @recvfrom(i32 %28, i8* %10, i32 80, i32 0, %struct.sockaddr* %44, i32* %5)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %43
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %10)
%52 = call i32 @close(i32 %28)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
ret i32 0
}