#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_addr;
  int /*<<< orphan*/ sin_port;
  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*/ do_cli(int /*<<< orphan*/, int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in servaddr;
  if (argc != 2) {
    printf("usage: udpclient <IPaddress>\n");
    exit(1);
  }
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(8888);
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
    printf("[%s] is not a valid IPaddress\n", argv[1]);
    exit(1);
  }
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  do_cli(stdin, sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a8 <main+0x38>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   1070 <bzero@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x22b8,%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
call   1060 <inet_pton@plt>
cmp    $0x0,%rax
jg     1213 <main+0xa3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    $0xc,%ecx
call   1030 <do_cli@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1205 <main+0x85>
mov    %rsi,%r15
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
mov    0x2e40(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edi
mov    0x8(%r15),%rsi
mov    %r14,%rdx
call   1070 <inet_pton@plt>
test   %rax,%rax
jle    121b <main+0x9b>
mov    (%rbx),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    0x2df8(%rip),%rcx
mov    (%rcx),%edi
mov    %rsp,%rdx
mov    %eax,%esi
mov    $0xc,%ecx
call   1030 <do_cli@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r15),%rsi
lea    0xdda(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [30 x i8] c"usage: udpclient <IPaddress>\0A\00"
@AF_INET = global i32 0
@.str.1 = [31 x i8] c"[%s] is not a valid IPaddress\0A\00"
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @htons(i32 8888)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%24 = call i64 @inet_pton(i32 %19, i8* %22, i32* %23)
%25 = icmp sle i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %13
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %13
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_DGRAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = load i32, i32* @stdin
%37 = load i32, i32* %6
%38 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%39 = call i32 @do_cli(i32 %36, i32 %37, %struct.sockaddr* %38, i32 12)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str.1 = [31 x i8] c"[%s] is not a valid IPaddress\0A\00"
@SOCK_DGRAM = global i32 0
@stdin = global i32 0
@str = [29 x i8] c"usage: udpclient <IPaddress>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 8888)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %13, i32* %14
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%19 = call i64 @inet_pton(i32 %15, i8* %17, i32* %18)
%20 = icmp slt i64 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %9
%22 = load i8*, i8** %16
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %9
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_DGRAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
%29 = load i32, i32* @stdin
%30 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%31 = call i32 @do_cli(i32 %29, i32 %28, %struct.sockaddr* %30, i32 12)
ret i32 0
}