#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*/ printf(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int /*<<< orphan*/ sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(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, cliaddr;
  char sendline[1000];
  char recvline[1000];
  if (argc != 2) {
    printf("usage:  udpcli <IP address>\n");
    exit(1);
  }
  sockfd = socket(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(sockfd, sendline, strlen(sendline), 0, (struct sockaddr *)&servaddr,
           sizeof(servaddr));
    n = recvfrom(sockfd, recvline, 10000, 0, NULL, NULL);
    recvline[n] = 0;
    fputs(recvline, stdout);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e9 <main+0x39>
lea    0xe26(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x7d00,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    -0x420(%rbp),%rdi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
mov    $0x2710,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     12ea <main+0x13a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x81c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x818(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x81c(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    -0x14(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10a0 <recvfrom@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x810(%rbp),%rdi
mov    0x2cea(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    123c <main+0x8c>
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7e8,%rsp
cmp    $0x2,%edi
jne    12c3 <main+0x113>
mov    %rsi,%rbx
mov    0x2e14(%rip),%r14
mov    (%r14),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    %rsp,%rdi
mov    $0xc,%esi
call   10b0 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x7d00,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    0x2dc2(%rip),%r12
mov    (%r12),%edx
lea    0x400(%rsp),%rdi
mov    $0x2710,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     12af <main+0xff>
lea    0x400(%rsp),%rbx
mov    %rsp,%r14
lea    0x10(%rsp),%r15
mov    0x2d78(%rip),%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10a0 <recvfrom@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1060 <fputs@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x2710,%esi
call   1080 <fgets@plt>
test   %rax,%rax
jne    1250 <main+0xa0>
xor    %eax,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd36(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10c0 <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"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@stdout = global i32 0
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 %struct.sockaddr_in
%10 = alloca [1000 x i8]
%11 = alloca [1000 x i8]
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, 2
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_DGRAM
%20 = call i32 @socket(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, %17
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, 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 %53
37: ; preds = %32
%38 = load i32, i32* %6
%39 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%43 = call i32 @sendto(i32 %38, i8* %39, i32 %41, i32 0, %struct.sockaddr* %42, i32 12)
%44 = load i32, i32* %6
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%46 = call i32 @recvfrom(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 [1000 x i8], [1000 x i8]* %11, i64 0, i64 %48
store i8 0, i8* %49
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%51 = load i32, i32* @stdout
%52 = call i32 @fputs(i8* %50, i32 %51)
br label %32
53: ; preds = %32
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@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 [1000 x i8]
%5 = alloca [1000 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1000 x i8], [1000 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 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @inet_addr(i8* %21)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 32000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* @stdin
%27 = call i32* @fgets(i8* %7, i32 10000, i32 %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %42, label %29
29: ; preds = %13
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %31
31: ; preds = %29, %31
%32 = call i32 @strlen(i8* %7)
%33 = call i32 @sendto(i32 %16, i8* %7, i32 %32, i32 0, %struct.sockaddr* %30, i32 12)
%34 = call i32 @recvfrom(i32 %16, i8* %8, i32 10000, i32 0, i32* null, i32* null)
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %35
store i8 0, i8* %36
%37 = load i32, i32* @stdout
%38 = call i32 @fputs(i8* %8, i32 %37)
%39 = load i32, i32* @stdin
%40 = call i32* @fgets(i8* %7, i32 10000, i32 %39)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %31
42: ; preds = %31, %13
ret i32 0
}