#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);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
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 = "Hello Server, I am Client.";
  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 (1) {
    int num = sendto(cliSocket, sendbuf, strlen(sendbuf) + 1, 0,
                     (struct sockaddr *)&servAddr, sizeof(servAddr));
    if (num == strlen(sendbuf) + 1)
      printf("Send: Hello Server, I am Client.\nlength:%d\n\n", num);
    else
      printf("send err\n");
    sleep(1);
  }
  close(cliSocket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1a0a,-0x1c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    11ea <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1239 <main+0xa9>
cmpl   $0x3,-0x8(%rbp)
jne    1215 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1234 <main+0xa4>
cmpl   $0x2,-0x8(%rbp)
jne    122f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1234 <main+0xa4>
jmp    1239 <main+0xa9>
lea    0xdf7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1281 <main+0xf1>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d60(%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   1070 <inet_aton@plt>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x28(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
jne    1326 <main+0x196>
mov    -0x3c(%rbp),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1334 <main+0x1a4>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <sleep@plt>
jmp    12ba <main+0x12a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x4,%edi
jl     11d8 <main+0x38>
mov    (%rsi),%rcx
lea    0xe4d(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2f(%rip),%r14
mov    $0x1a0a,%ebp
jmp    1203 <main+0x63>
lea    0xe21(%rip),%r14
cmp    $0x2,%edi
je     11f8 <main+0x58>
mov    $0x1a0a,%ebp
cmp    $0x3,%edi
jne    1203 <main+0x63>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%rdi
jmp    11fc <main+0x5c>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x2dde(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
test   %eax,%eax
js     12d2 <main+0x132>
mov    %eax,%r13d
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <inet_aton@plt>
lea    0xe0e(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd5(%rip),%rbp
lea    0xe0d(%rip),%r14
lea    0xe33(%rip),%r12
jmp    1292 <main+0xf2>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13d,%edi
mov    %rbp,%rsi
xor    %ecx,%ecx
mov    %r15,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    %eax,%ebx
jne    1280 <main+0xe0>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1288 <main+0xe8>
lea    0xd79(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <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"
@.str.2 = [27 x i8] c"Hello Server, I am Client.\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@.str.5 = [45 x i8] c"Send: Hello Server, I am Client.\0Alength:%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 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
store i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8** %10
%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.3, 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.4, i64 0, i64 0), i8* %63, i32 %64)
br label %66
66: ; preds = %54, %84
%67 = load i32, i32* %9
%68 = load i8*, i8** %10
%69 = load i8*, i8** %10
%70 = call i32 @strlen(i8* %69)
%71 = add nsw i32 %70, 1
%72 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%73 = call i32 @sendto(i32 %67, i8* %68, i32 %71, i32 0, %struct.sockaddr* %72, i32 12)
store i32 %73, i32* %11
%74 = load i32, i32* %11
%75 = load i8*, i8** %10
%76 = call i32 @strlen(i8* %75)
%77 = add nsw i32 %76, 1
%78 = icmp eq i32 %74, %77
br i1 %78, label %79, label %82
79: ; preds = %66
%80 = load i32, i32* %11
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %80)
br label %84
82: ; preds = %66
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %84
84: ; preds = %82, %79
%85 = call i32 @sleep(i32 1)
br label %66
}

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"
@.str.2 = [27 x i8] c"Hello Server, I am Client.\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.3 = [11 x i8] c"socket err\00"
@.str.4 = [25 x i8] c"Send data to %s:%d ...\0A\0A\00"
@.str.5 = [45 x i8] c"Send: Hello Server, I am Client.\0Alength:%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 = icmp sgt i32 %0, 3
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %6, i8* %6)
br label %19
8: ; preds = %2
switch i32 %0, label %19 [
i32 3, label %9
i32 2, label %15
]
9: ; preds = %8
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
br label %19
15: ; preds = %8
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
br label %19
19: ; preds = %8, %9, %15, %5
%20 = phi i32 [ 6666, %5 ], [ %14, %9 ], [ %18, %15 ], [ 6666, %8 ]
%21 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %5 ], [ %11, %9 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %15 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %8 ]
%22 = bitcast %struct.sockaddr_in* %3 to i8*
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_DGRAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %19
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %31, i32* %32
%33 = tail call i32 @htons(i32 %20)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %33, i32* %34
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%36 = call i32 @inet_aton(i8* %21, i32* %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %21, i32 %20)
%38 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %39
39: ; preds = %50, %30
%40 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%41 = add nsw i32 %40, 1
%42 = call i32 @sendto(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 0, %struct.sockaddr* %38, i32 12)
%43 = call i32 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%44 = add nsw i32 %43, 1
%45 = icmp eq i32 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %39
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %42)
br label %50
48: ; preds = %39
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %50
50: ; preds = %48, %46
%51 = call i32 @sleep(i32 1)
br label %39
}