#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ udp_respon(int, struct sockaddr *, int);
int main(int argc, char *argv[]) {
  int sockfd;
  struct sockaddr_in server_addr;
  if (argc != 2) {
    printf("Usage: %s server_ip\n", argv[0]);
    return -1;
  }
  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("create socket error");
    return 1;
  }
  puts("create socket done!");
  bzero(&server_addr, sizeof(struct sockaddr_in));
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(8888);
  if (inet_aton(argv[1], &server_addr.sin_addr) < 0) {
    perror("server ip address error");
    return -2;
  }
  udp_respon(sockfd, (struct sockaddr *)&server_addr,
             sizeof(struct sockaddr_in));
  close(sockfd);
  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     11cf <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1292 <main+0x102>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    120c <main+0x7c>
lea    0xe1a(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1292 <main+0x102>
lea    0xe16(%rip),%rdi
call   1030 <puts@plt>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <inet_aton@plt>
cmp    $0x0,%rax
jge    1272 <main+0xe2>
lea    0xddc(%rip),%rdi
call   1090 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1292 <main+0x102>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1040 <udp_respon@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    122b <main+0x9b>
mov    0x2e3b(%rip),%r15
mov    (%r15),%edi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     124a <main+0xba>
mov    %eax,%ebp
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10a0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    $0x22b8,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x8(%rbx),%rdi
mov    %r14,%rsi
call   1080 <inet_aton@plt>
test   %rax,%rax
js     125d <main+0xcd>
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1040 <udp_respon@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
jmp    123f <main+0xaf>
mov    (%rbx),%rsi
lea    0xdcb(%rip),%rdi
call   1060 <printf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc4(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    123f <main+0xaf>
lea    0xdd9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xfffffffe,%eax
jmp    123f <main+0xaf>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s server_ip\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [20 x i8] c"create socket error\00"
@.str.2 = [20 x i8] c"create socket done!\00"
@.str.3 = [24 x i8] c"server ip address error\00"
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 %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 -1, i32* %3
br label %43
15: ; preds = %2
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_DGRAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %43
22: ; preds = %15
%23 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %25, i32* %26
%27 = call i32 @htons(i32 8888)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%33 = call i64 @inet_aton(i8* %31, i32* %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %3
br label %43
37: ; preds = %22
%38 = load i32, i32* %6
%39 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%40 = call i32 @udp_respon(i32 %38, %struct.sockaddr* %39, i32 12)
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
store i32 0, i32* %3
br label %43
43: ; preds = %37, %35, %20, %10
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s server_ip\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [20 x i8] c"create socket error\00"
@.str.2 = [20 x i8] c"create socket done!\00"
@.str.3 = [24 x i8] c"server ip address error\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 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %34
9: ; preds = %2
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_DGRAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %34
16: ; preds = %9
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 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 = tail call i32 @htons(i32 8888)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%26 = call i64 @inet_aton(i8* %24, i32* %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %34
30: ; preds = %16
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%32 = call i32 @udp_respon(i32 %12, %struct.sockaddr* %31, i32 12)
%33 = call i32 @close(i32 %12)
br label %34
34: ; preds = %30, %28, %14, %6
%35 = phi i32 [ -1, %6 ], [ 1, %14 ], [ -2, %28 ], [ 0, %30 ]
ret i32 %35
}