#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 {
  TYPE_1__ sin_addr;
  void *sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ s_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
void *htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  struct sockaddr_in s_addr;
  int sock;
  int addr_len;
  int len;
  char buff[128];
  if (argc != 3) {
    printf("Usage: ./udpSend ip port \n");
    return -1;
  }
  if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
    perror("socket");
    exit(errno);
  } else
    printf("create socket.\n\r");
  s_addr.sin_family = AF_INET;
  if (argv[2])
    s_addr.sin_port = htons(atoi(argv[2]));
  else
    s_addr.sin_port = htons(1234);
  if (argv[1])
    s_addr.sin_addr.s_addr = inet_addr(argv[1]);
  else {
    printf("server ip not exist.\n");
    exit(0);
  }
  addr_len = sizeof(s_addr);
  strcpy(buff, "hello i'm here");
  len =
      sendto(sock, buff, strlen(buff), 0, (struct sockaddr *)&s_addr, addr_len);
  if (len < 0) {
    printf("\n\rsend error.\n\r");
    return 3;
  }
  printf("send success.\n\r");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11db <main+0x3b>
lea    0xe36(%rip),%rdi
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1336 <main+0x196>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    121a <main+0x7a>
lea    0xe14(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
lea    0xe01(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     125e <main+0xbe>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %rax,-0x20(%rbp)
jmp    126c <main+0xcc>
mov    $0x4d2,%edi
call   1050 <htons@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1290 <main+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x28(%rbp)
jmp    12a3 <main+0x103>
lea    0xd9c(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
movl   $0x18,-0x30(%rbp)
lea    -0xc0(%rbp),%rdi
lea    0xd91(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xcc(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0xc0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xcc(%rbp),%edi
mov    -0xc8(%rbp),%rsi
mov    %eax,%edx
lea    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9d
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1323 <main+0x183>
lea    0xd46(%rip),%rdi
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    1336 <main+0x196>
lea    0xd3e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
cmp    $0x3,%edi
jne    120e <main+0x5e>
mov    %rsi,%rbx
mov    0x2e1e(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12b2 <main+0x102>
mov    %eax,%r14d
lea    0xe17(%rip),%rdi
call   1070 <printf@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rbx),%rdi
test   %rdi,%rdi
je     1224 <main+0x74>
call   10b0 <atoi@plt>
mov    %eax,%edi
jmp    1229 <main+0x79>
lea    0xe47(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    12a4 <main+0xf4>
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %rax,0x10(%rsp)
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
je     12cc <main+0x11c>
call   1090 <inet_addr@plt>
mov    %eax,0x8(%rsp)
lea    0xdc8(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    $0x18,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
js     1293 <main+0xe3>
lea    0xdab(%rip),%rdi
call   1070 <printf@plt>
jmp    12a4 <main+0xf4>
lea    0xd8d(%rip),%rdi
call   1070 <printf@plt>
mov    $0x3,%ebx
mov    %ebx,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd47(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    0xd74(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"Usage: ./udpSend ip port \0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.2 = [17 x i8] c"create socket.\0A\0D\00"
@.str.3 = [22 x i8] c"server ip not exist.\0A\00"
@.str.4 = [15 x i8] c"hello i'm here\00"
@.str.5 = [16 x i8] c"\0A\0Dsend error.\0A\0D\00"
@.str.6 = [16 x i8] c"send success.\0A\0D\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %74
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* %7
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @errno
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
%38 = call i8* @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %38, i8** %39
br label %43
40: ; preds = %26
%41 = call i8* @htons(i32 1234)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i8* %41, i8** %42
br label %43
43: ; preds = %40, %33
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 1
%46 = load i8*, i8** %45
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %55
48: ; preds = %43
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @inet_addr(i8* %51)
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
br label %58
55: ; preds = %43
%56 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %48
store i32 24, i32* %8
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%60 = call i32 @strcpy(i8* %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32, i32* %7
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%64 = call i32 @strlen(i8* %63)
%65 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%66 = load i32, i32* %8
%67 = call i32 @sendto(i32 %61, i8* %62, i32 %64, i32 0, %struct.sockaddr* %65, i32 %66)
store i32 %67, i32* %9
%68 = load i32, i32* %9
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %58
%71 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
store i32 3, i32* %3
br label %74
72: ; preds = %58
%73 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %74
74: ; preds = %72, %70, %13
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.2 = [17 x i8] c"create socket.\0A\0D\00"
@.str.4 = [15 x i8] c"hello i'm here\00"
@.str.5 = [16 x i8] c"\0A\0Dsend error.\0A\0D\00"
@.str.6 = [16 x i8] c"send success.\0A\0D\00"
@str = [21 x i8] c"server ip not exist.\00"
@str.7 = [26 x i8] c"Usage: ./udpSend ip port \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [128 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.7, i64 0, i64 0))
br label %50
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @errno
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = icmp eq i8* %24, null
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = tail call i32 @atoi(i8* %24)
br label %28
28: ; preds = %19, %26
%29 = phi i32 [ %27, %26 ], [ 1234, %19 ]
%30 = tail call i8* @htons(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i8* %30, i8** %31
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %43, label %35
35: ; preds = %28
%36 = tail call i32 @inet_addr(i8* %33)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %36, i32* %37
%38 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @strlen(i8* %6)
%40 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %13, i8* %6, i32 %39, i32 0, %struct.sockaddr* %40, i32 24)
%42 = icmp slt i32 %41, 0
br i1 %42, label %46, label %48
43: ; preds = %28
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%45 = tail call i32 @exit(i32 0)
unreachable
46: ; preds = %35
%47 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %50
48: ; preds = %35
%49 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %48, %46, %8
%51 = phi i32 [ -1, %8 ], [ 3, %46 ], [ 0, %48 ]
ret i32 %51
}