#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 /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
scalar_t__ 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 Count, char *Strings[]) {
  char buffer[1024];
  struct sockaddr_in addr;
  int sd, addr_size;
  if (Count != 2) {
    printf("usage: %s <msg>\n", Strings[0]);
    exit(0);
  }
  if ((sd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
    perror("Socket");
    abort();
  }
  addr.sin_family = AF_INET;
  addr.sin_port = htons(9999);
  if (inet_aton("127.0.0.1", &addr.sin_addr) == 0) {
    perror("127.0.0.1");
    abort();
  }
  sendto(sd, Strings[1], strlen(Strings[1]) + 1, 0, (struct sockaddr *)&addr,
         sizeof(addr));
  bzero(buffer, 1024);
  addr_size = sizeof(addr);
  if (recvfrom(sd, buffer, 1024, 0, (struct sockaddr *)&addr, &addr_size) < 0)
    perror("server reply");
  else
    printf("Reply: %s:%d \"%s\"\n", inet_ntoa(addr.sin_addr),
           ntohs(addr.sin_port), buffer);
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x424(%rbp)
cmp    $0x0,%eax
jge    125a <main+0x7a>
lea    0xdc3(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x418(%rbp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,-0x420(%rbp)
lea    -0x420(%rbp),%rsi
add    $0x4,%rsi
lea    0xd8d(%rip),%rdi
call   10a0 <inet_aton@plt>
cmp    $0x0,%rax
jne    12ad <main+0xcd>
lea    0xd77(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x424(%rbp),%eax
mov    %eax,-0x434(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x434(%rbp),%edi
mov    -0x430(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x420(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   10e0 <bzero@plt>
movl   $0xc,-0x428(%rbp)
mov    -0x424(%rbp),%edi
lea    -0x410(%rbp),%rsi
lea    -0x420(%rbp),%r8
mov    $0x400,%edx
xor    %ecx,%ecx
lea    -0x428(%rbp),%r9
call   10b0 <recvfrom@plt>
cmp    $0x0,%rax
jge    135a <main+0x17a>
lea    0xcd2(%rip),%rdi
call   10d0 <perror@plt>
jmp    1395 <main+0x1b5>
mov    -0x41c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x440(%rbp)
mov    -0x420(%rbp),%edi
call   10c0 <ntohs@plt>
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
lea    -0x410(%rbp),%rcx
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x424(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jne    12fd <main+0x11d>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     1315 <main+0x135>
mov    %eax,%ebp
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x270f,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
lea    0x4(%rsp),%rsi
lea    0xdd8(%rip),%rdi
call   10a0 <inet_aton@plt>
test   %rax,%rax
je     131e <main+0x13e>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%r14
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   10e0 <bzero@plt>
movl   $0xc,0xc(%rsp)
lea    0xc(%rsp),%r9
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   10b0 <recvfrom@plt>
test   %rax,%rax
js     12ef <main+0x10f>
mov    0x4(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbx
mov    (%rsp),%edi
call   10c0 <ntohs@plt>
lea    0xd66(%rip),%rdi
lea    0x10(%rsp),%rcx
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd2c(%rip),%rdi
call   10d0 <perror@plt>
jmp    12da <main+0xfa>
mov    (%r14),%rsi
lea    0xcf9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
lea    0xcf5(%rip),%rdi
jmp    1325 <main+0x145>
lea    0xcf3(%rip),%rdi
call   10d0 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"usage: %s <msg>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [13 x i8] c"server reply\00"
@.str.4 = [19 x i8] c"Reply: %s:%d \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%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 ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_DGRAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %8
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %18
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %27, i32* %28
%29 = call i32 @htons(i32 9999)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%32 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %26
%35 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (...) @abort()
unreachable
37: ; preds = %26
%38 = load i32, i32* %8
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i64 @strlen(i8* %44)
%46 = add nsw i64 %45, 1
%47 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%48 = call i32 @sendto(i32 %38, i8* %41, i64 %46, i32 0, %struct.sockaddr* %47, i32 12)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = call i32 @bzero(i8* %49, i32 1024)
store i32 12, i32* %9
%51 = load i32, i32* %8
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%54 = call i64 @recvfrom(i32 %51, i8* %52, i32 1024, i32 0, %struct.sockaddr* %53, i32* %9)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %37
%57 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %67
58: ; preds = %37
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%60 = load i32, i32* %59
%61 = call i8* @inet_ntoa(i32 %60)
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i32 @ntohs(i32 %63)
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%66 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %61, i32 %64, i8* %65)
br label %67
67: ; preds = %58, %56
%68 = load i32, i32* %8
%69 = call i32 @close(i32 %68)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [17 x i8] c"usage: %s <msg>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"Socket\00"
@AF_INET = global i32 0
@.str.2 = [10 x i8] c"127.0.0.1\00"
@.str.3 = [13 x i8] c"server reply\00"
@.str.4 = [19 x i8] c"Reply: %s:%d \22%s\22\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = icmp eq i32 %0, 2
br i1 %9, label %14, label %10
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 (...) @abort()
unreachable
22: ; preds = %14
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 9999)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%28 = call i64 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 (...) @abort()
unreachable
33: ; preds = %22
%34 = getelementptr inbounds i8*, i8** %1, i64 1
%35 = load i8*, i8** %34
%36 = call i64 @strlen(i8* dereferenceable(1) %35)
%37 = add nsw i64 %36, 1
%38 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%39 = call i32 @sendto(i32 %17, i8* %35, i64 %37, i32 0, %struct.sockaddr* %38, i32 12)
%40 = call i32 @bzero(i8* %6, i32 1024)
store i32 12, i32* %5
%41 = call i64 @recvfrom(i32 %17, i8* %6, i32 1024, i32 0, %struct.sockaddr* %38, i32* %5)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %33
%44 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %51
45: ; preds = %33
%46 = load i32, i32* %27
%47 = call i8* @inet_ntoa(i32 %46)
%48 = load i32, i32* %26
%49 = call i32 @ntohs(i32 %48)
%50 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %47, i32 %49, i8* %6)
br label %51
51: ; preds = %45, %43
%52 = call i32 @close(i32 %17)
ret i32 0
}