#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 */
typedef int /*<<< orphan*/ your_adr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ msg3;
typedef int /*<<< orphan*/ msg2;
typedef int /*<<< orphan*/ msg1;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error_handling(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char msg1[] = "Hi!";
  char msg2[] = "I'm another UDP host!";
  char msg3[] = "Nice to meet you";
  int sock;
  struct sockaddr_in your_adr;
  socklen_t your_adr_sz;
  if (argc != 3) {
    printf("Usage: %s <IP> <port>\n", argv[0]);
    exit(1);
  }
  sock = socket(PF_INET, SOCK_DGRAM, 0);
  if (sock == -1)
    error_handling("socket() error");
  memset(&your_adr, 0, sizeof(your_adr));
  your_adr.sin_family = AF_INET;
  your_adr.sin_addr.s_addr = inet_addr(argv[1]);
  your_adr.sin_port = htons(atoi(argv[2]));
  sendto(sock, msg1, sizeof(msg1), 0, (struct sockaddr *)&your_adr,
         sizeof(your_adr));
  sendto(sock, msg2, sizeof(msg2), 0, (struct sockaddr *)&your_adr,
         sizeof(your_adr));
  sendto(sock, msg3, sizeof(msg3), 0, (struct sockaddr *)&your_adr,
         sizeof(your_adr));
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe44(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0xe6a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe67(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xe65(%rip),%eax
mov    %eax,-0x20(%rbp)
mov    0xe5f(%rip),%ax
mov    %ax,-0x1c(%rbp)
mov    0xe60(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe5d(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe5b(%rip),%al
mov    %al,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     122f <main+0x8f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde4(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1261 <main+0xc1>
lea    0xdbf(%rip),%rdi
call   1090 <error_handling@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x60(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x14(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x54(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x16,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x54(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x60(%rbp),%r8
mov    $0x11,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    -0x54(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%r15
movl   $0x216948,0xc(%rsp)
movaps 0xe45(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movabs $0x2174736f682050,%rax
mov    %rax,0x4e(%rsp)
movaps 0xe4a(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movb   $0x0,0x30(%rsp)
cmp    $0x3,%edi
jne    12be <main+0x11e>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1215 <main+0x75>
lea    0xe38(%rip),%rdi
call   1090 <error_handling@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r15),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%r15),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
mov    $0x16,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x11,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1060 <sendto@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r15),%rsi
lea    0xd69(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg1 = [4 x i8] c"Hi!\00"
@__const.main.msg2 = [22 x i8] c"I'm another UDP host!\00"
@__const.main.msg3 = [17 x i8] c"Nice to meet you\00"
@.str = [23 x i8] c"Usage: %s <IP> <port>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i8]
%7 = alloca [22 x i8]
%8 = alloca [17 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [4 x i8]* %6 to i8*
%13 = bitcast [22 x i8]* %7 to i8*
%14 = bitcast [17 x i8]* %8 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 3
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32, i32* @PF_INET
%25 = load i32, i32* @SOCK_DGRAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = call i32 @memset(%struct.sockaddr_in* %10, i32 0, i32 12)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %33, i32* %34
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @inet_addr(i8* %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%40 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %39, i32 0, i32 0
store i32 %38, i32* %40
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = call i32 @htons(i32 %44)
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %45, i32* %46
%47 = load i32, i32* %9
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%49 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%50 = call i32 @sendto(i32 %47, i8* %48, i32 4, i32 0, %struct.sockaddr* %49, i32 12)
%51 = load i32, i32* %9
%52 = getelementptr inbounds [22 x i8], [22 x i8]* %7, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%54 = call i32 @sendto(i32 %51, i8* %52, i32 22, i32 0, %struct.sockaddr* %53, i32 12)
%55 = load i32, i32* %9
%56 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%57 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%58 = call i32 @sendto(i32 %55, i8* %56, i32 17, i32 0, %struct.sockaddr* %57, i32 12)
%59 = load i32, i32* %9
%60 = call i32 @close(i32 %59)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.msg2 = [22 x i8] c"I'm another UDP host!\00"
@__const.main.msg3 = [17 x i8] c"Nice to meet you\00"
@.str = [23 x i8] c"Usage: %s <IP> <port>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [15 x i8] c"socket() error\00"
@AF_INET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [22 x i8]
%5 = alloca [17 x i8]
%6 = alloca %struct.sockaddr_in
%7 = bitcast i32* %3 to i8*
store i32 2189640, i32* %3
%8 = getelementptr inbounds [22 x i8], [22 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %6 to i8*
%11 = icmp eq i32 %0, 3
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_DGRAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @error_handling(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %16
%24 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
%34 = call i32 @htons(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %34, i32* %35
%36 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%37 = call i32 @sendto(i32 %19, i8* %7, i32 4, i32 0, %struct.sockaddr* %36, i32 12)
%38 = call i32 @sendto(i32 %19, i8* %8, i32 22, i32 0, %struct.sockaddr* %36, i32 12)
%39 = call i32 @sendto(i32 %19, i8* %9, i32 17, i32 0, %struct.sockaddr* %36, i32 12)
%40 = call i32 @close(i32 %19)
ret i32 0
}