#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 atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char *argv[]) {
  char *SERVER_IP = "127.0.0.1";
  int SERVER_PORT = 6666;
  if (argc > 3)
    printf("param err:\nUsage: %s ip port | %s port | %s\n", argv[0], argv[0],
           argv[0]);
  else if (argc == 3) {
    SERVER_IP = argv[1];
    SERVER_PORT = atoi(argv[2]);
  } else if (argc == 2)
    SERVER_PORT = atoi(argv[1]);
  struct sockaddr_in servAddr;
  int cliSocket;
  char sendbuf[200];
  if ((cliSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
    printf("socket err");
    exit(1);
  }
  servAddr.sin_family = AF_INET;
  servAddr.sin_port = htons(SERVER_PORT);
  inet_aton(SERVER_IP, &servAddr.sin_addr);
  printf("Send data to %s:%d ...\n\n", SERVER_IP, SERVER_PORT);
  while (fgets(sendbuf, 200, stdin)) {
    printf("Send: %s\n", sendbuf);
    int num = sendto(cliSocket, sendbuf, strlen(sendbuf), 0,
                     (struct sockaddr *)&servAddr, sizeof(servAddr));
    if (num == strlen(sendbuf))
      printf("Send scuccess, length:%d\n\n", num);
    else
      printf("send err\n");
    memset(sendbuf, 0, 200);
  }
  close(cliSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1a0a,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    120d <main+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    125c <main+0xac>
cmpl   $0x3,-0x8(%rbp)
jne    1238 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1257 <main+0xa7>
cmpl   $0x2,-0x8(%rbp)
jne    1252 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1257 <main+0xa7>
jmp    125c <main+0xac>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1299 <main+0xe9>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <inet_aton@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xd77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x100(%rbp),%rdi
mov    0x2d00(%rip),%rax
mov    (%rax),%edx
mov    $0xc8,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13bb <main+0x20b>
lea    -0x100(%rbp),%rsi
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x114(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x110(%rbp)
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x114(%rbp),%edi
mov    -0x110(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x104(%rbp)
mov    -0x104(%rbp),%eax
mov    %eax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x108(%rbp),%eax
cmp    %ecx,%eax
jne    1395 <main+0x1e5>
mov    -0x104(%rbp),%esi
lea    0xcdc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13a3 <main+0x1f3>
lea    0xce4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
jmp    12d2 <main+0x122>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
cmp    $0x4,%edi
jl     11fb <main+0x3b>
mov    (%rsi),%rcx
lea    0xe2a(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe0c(%rip),%r14
mov    $0x1a0a,%ebx
jmp    1226 <main+0x66>
lea    0xdfe(%rip),%r14
cmp    $0x2,%edi
je     121b <main+0x5b>
mov    $0x1a0a,%ebx
cmp    $0x3,%edi
jne    1226 <main+0x66>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
jmp    121f <main+0x5f>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %eax,%ebx
mov    0x2dbb(%rip),%r15
mov    (%r15),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     134b <main+0x18b>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   10b0 <inet_aton@plt>
lea    0xdd4(%rip),%rdi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2d5f(%rip),%r13
mov    0x0(%r13),%edx
lea    0x10(%rsp),%rdi
mov    $0xc8,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     1330 <main+0x170>
lea    0xdb7(%rip),%r14
lea    0x10(%rsp),%rbx
mov    %rsp,%r15
jmp    12e1 <main+0x121>
xchg   %ax,%ax
lea    0xdc9(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1070 <memset@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0xc8,%esi
call   10a0 <fgets@plt>
test   %rax,%rax
je     1330 <main+0x170>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r12d
jne    12b0 <main+0xf0>
lea    0xd41(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12bc <main+0xfc>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce5(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [11 x i8] c"socket err\00"
@.str.3 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@stdin = global i32 0
@.str.4 = [10 x i8] c"Send: %s\0A\00"
@.str.5 = [27 x i8] c"Send scuccess, length:%d\0A\0A\00"
@.str.6 = [10 x i8] c"send err\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [200 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 6666, i32* %7
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 3
br i1 %13, label %14, label %25
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %20, i8* %23)
br label %46
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 3
br i1 %27, label %28, label %36
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
store i8* %31, i8** %6
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %7
br label %45
36: ; preds = %25
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, 2
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %7
br label %44
44: ; preds = %39, %36
br label %45
45: ; preds = %44, %28
br label %46
46: ; preds = %45, %14
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_DGRAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %9
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i32, i32* @AF_INET
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %55, i32* %56
%57 = load i32, i32* %7
%58 = call i32 @htons(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %58, i32* %59
%60 = load i8*, i8** %6
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%62 = call i32 @inet_aton(i8* %60, i32* %61)
%63 = load i8*, i8** %6
%64 = load i32, i32* %7
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %63, i32 %64)
br label %66
66: ; preds = %89, %54
%67 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%68 = load i32, i32* @stdin
%69 = call i64 @fgets(i8* %67, i32 200, i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %92
71: ; preds = %66
%72 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %72)
%74 = load i32, i32* %9
%75 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%76 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%79 = call i32 @sendto(i32 %74, i8* %75, i32 %77, i32 0, %struct.sockaddr* %78, i32 12)
store i32 %79, i32* %11
%80 = load i32, i32* %11
%81 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%82 = call i32 @strlen(i8* %81)
%83 = icmp eq i32 %80, %82
br i1 %83, label %84, label %87
84: ; preds = %71
%85 = load i32, i32* %11
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %85)
br label %89
87: ; preds = %71
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %89
89: ; preds = %87, %84
%90 = getelementptr inbounds [200 x i8], [200 x i8]* %10, i64 0, i64 0
%91 = call i32 @memset(i8* %90, i32 0, i32 200)
br label %66
92: ; preds = %66
%93 = load i32, i32* %9
%94 = call i32 @close(i32 %93)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [45 x i8] c"param err:\0AUsage: %s ip port | %s port | %s\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.2 = [11 x i8] c"socket err\00"
@.str.3 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@stdin = global i32 0
@.str.4 = [10 x i8] c"Send: %s\0A\00"
@.str.5 = [27 x i8] c"Send scuccess, length:%d\0A\0A\00"
@str = [9 x i8] c"send err\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [200 x i8]
%5 = icmp sgt i32 %0, 3
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %7, i8* %7)
br label %20
9: ; preds = %2
switch i32 %0, label %20 [
i32 3, label %10
i32 2, label %16
]
10: ; preds = %9
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
br label %20
16: ; preds = %9
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
br label %20
20: ; preds = %9, %10, %16, %6
%21 = phi i32 [ 6666, %6 ], [ %15, %10 ], [ %19, %16 ], [ 6666, %9 ]
%22 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %6 ], [ %12, %10 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %16 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %9 ]
%23 = bitcast %struct.sockaddr_in* %3 to i8*
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %4, i64 0, i64 0
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_DGRAM
%27 = tail call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %33, i32* %34
%35 = tail call i32 @htons(i32 %21)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%38 = call i32 @inet_aton(i8* %22, i32* %37)
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %22, i32 %21)
%40 = load i32, i32* @stdin
%41 = call i64 @fgets(i8* %24, i32 200, i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %60, label %43
43: ; preds = %32
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %45
45: ; preds = %43, %55
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%47 = call i32 @strlen(i8* %24)
%48 = call i32 @sendto(i32 %27, i8* %24, i32 %47, i32 0, %struct.sockaddr* %44, i32 12)
%49 = call i32 @strlen(i8* %24)
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i32 %48)
br label %55
53: ; preds = %45
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %55
55: ; preds = %53, %51
%56 = call i32 @memset(i8* %24, i32 0, i32 200)
%57 = load i32, i32* @stdin
%58 = call i64 @fgets(i8* %24, i32 200, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %45
60: ; preds = %55, %32
%61 = call i32 @close(i32 %27)
ret i32 0
}