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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ init_dns(char *);
int /*<<< orphan*/ printf(char *);
int recvfrom_dns(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto_dns(int, char *, int /*<<< orphan*/,
                              int /*<<< orphan*/, struct sockaddr *, int);
int socket_dns(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sockfd, n;
  struct sockaddr_in servaddr;
  char sendline[10000];
  char recvline[10000];
  if (argc != 2) {
    printf("usage:  udpcli <IP address>\n");
    exit(1);
  }
  init_dns("a.a");
  sockfd = socket_dns(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  servaddr.sin_port = htons(32000);
  while (fgets(sendline, 10000, stdin) != NULL) {
    sendto_dns(sockfd, sendline, strlen(sendline), 0,
               (struct sockaddr *)&servaddr, sizeof(servaddr));
    n = recvfrom_dns(sockfd, recvline, 10000, 0, NULL, NULL);
    recvline[n] = 0;
    fputs(recvline, stdout);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f9 <main+0x39>
lea    0xe16(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xe1d(%rip),%rdi
call   10b0 <init_dns@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket_dns@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2db2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x7d00,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    -0x2740(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1312 <main+0x152>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4e5c(%rbp)
lea    -0x2740(%rbp),%rax
mov    %rax,-0x4e58(%rbp)
lea    -0x2740(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4e5c(%rbp),%edi
mov    -0x4e58(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1030 <sendto_dns@plt>
mov    -0x14(%rbp),%edi
lea    -0x4e50(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   1090 <recvfrom_dns@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x4e50(%rbp,%rax,1)
lea    -0x4e50(%rbp),%rdi
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
call   1070 <fputs@plt>
lea    0xd13(%rip),%rdi
call   1060 <printf@plt>
jmp    1258 <main+0x98>
xor    %eax,%eax
add    $0x4e60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e38,%rsp
cmp    $0x2,%edi
jne    12fd <main+0x12d>
mov    %rsi,%rbx
lea    0xe0c(%rip),%rdi
call   10c0 <init_dns@plt>
mov    0x2de8(%rip),%r14
mov    (%r14),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket_dns@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x7d00,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    0x2d96(%rip),%r12
mov    (%r12),%edx
lea    0x2720(%rsp),%rdi
mov    $0x2710,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     12e9 <main+0x119>
lea    0x2720(%rsp),%rbx
mov    %rsp,%r14
lea    0x10(%rsp),%r15
mov    0x2d48(%rip),%r13
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1050 <sendto_dns@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom_dns@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1080 <fputs@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1090 <fgets@plt>
test   %rax,%rax
jne    1280 <main+0xb0>
xor    %eax,%eax
add    $0x4e38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd00(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"usage: udpcli <IP address>\0A\00"
@.str.1 = [4 x i8] c"a.a\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca [10000 x i8]
%10 = alloca [10000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = call i32 @init_dns(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket_dns(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %22, i32* %23
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @inet_addr(i8* %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, 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 32000)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %30, i32* %31
br label %32
32: ; preds = %37, %16
%33 = getelementptr inbounds [10000 x i8], [10000 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32* @fgets(i8* %33, i32 10000, i32 %34)
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %54
37: ; preds = %32
%38 = load i32, i32* %6
%39 = getelementptr inbounds [10000 x i8], [10000 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [10000 x i8], [10000 x i8]* %9, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = call i32 @sendto_dns(i32 %38, i8* %39, i32 %41, i32 0, %struct.sockaddr* %42, i32 12)
%44 = load i32, i32* %6
%45 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%46 = call i32 @recvfrom_dns(i32 %44, i8* %45, i32 10000, i32 0, i32* null, i32* null)
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 %48
store i8 0, i8* %49
%50 = getelementptr inbounds [10000 x i8], [10000 x i8]* %10, i64 0, i64 0
%51 = load i32, i32* @stdout
%52 = call i32 @fputs(i8* %50, i32 %51)
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %32
54: ; preds = %32
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.1 = [4 x i8] c"a.a\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@stdout = global i32 0
@str = [28 x i8] c"usage: udpcli <IP address>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [10000 x i8]
%5 = alloca [10000 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32 @init_dns(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket_dns(i32 %15, i32 %16, i32 0)
%18 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @inet_addr(i8* %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 32000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = load i32, i32* @stdin
%28 = call i32* @fgets(i8* %7, i32 10000, i32 %27)
%29 = icmp eq i32* %28, null
br i1 %29, label %44, label %30
30: ; preds = %13
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %32
32: ; preds = %30, %32
%33 = call i32 @strlen(i8* %7)
%34 = call i32 @sendto_dns(i32 %17, i8* %7, i32 %33, i32 0, %struct.sockaddr* %31, i32 12)
%35 = call i32 @recvfrom_dns(i32 %17, i8* %8, i32 10000, i32 0, i32* null, i32* null)
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* @stdout
%39 = call i32 @fputs(i8* %8, i32 %38)
%40 = call i32 @putchar(i32 10)
%41 = load i32, i32* @stdin
%42 = call i32* @fgets(i8* %7, i32 10000, i32 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %32
44: ; preds = %32, %13
ret i32 0
}