#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*/ si_other;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ on_err(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int s = -1;
  struct sockaddr_in si_other;
  int slen = sizeof(si_other);
  char buf[512];
  if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    on_err(strerror(errno));
  memset((char *)&si_other, 0, sizeof(si_other));
  si_other.sin_family = AF_INET;
  si_other.sin_port = htons(atoi(argv[2]));
  if (inet_aton(argv[1], &si_other.sin_addr) == 0) {
    fprintf(stderr, "inet_aton() failed\n");
    exit(1);
  }
  for (int i = 0; i < 10; i++) {
    printf("Sending packet %d\n", i);
    sprintf(buf, "This is packet %d\n", i);
    if (sendto(s, buf, 512, 0, (struct sockaddr *)&si_other, slen) == -1)
      on_err(strerror(errno));
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xc,-0x24(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    0x2da8(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1238 <main+0x68>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %eax,%edi
call   1050 <on_err@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <inet_aton@plt>
cmp    $0x0,%rax
jne    12a5 <main+0xd5>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x234(%rbp)
cmpl   $0xa,-0x234(%rbp)
jge    133c <main+0x16c>
mov    -0x234(%rbp),%esi
lea    0xd4b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x230(%rbp),%rdi
mov    -0x234(%rbp),%edx
lea    0xd45(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
lea    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
mov    $0x200,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1323 <main+0x153>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %eax,%edi
call   1050 <on_err@plt>
jmp    1328 <main+0x158>
mov    -0x234(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x234(%rbp)
jmp    12af <main+0xdf>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
mov    0x2dfd(%rip),%r15
mov    (%r15),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2dba(%rip),%rax
mov    (%rax),%edx
call   10f0 <socket@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
jne    1222 <main+0x52>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %eax,%edi
call   1050 <on_err@plt>
mov    %rsp,%rbx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%r14),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%r14),%rdi
mov    %rbx,%rsi
call   10a0 <inet_aton@plt>
test   %rax,%rax
je     12f2 <main+0x122>
lea    0xda7(%rip),%r14
lea    0xdb3(%rip),%r15
lea    0x10(%rsp),%rbx
mov    %rsp,%r13
jmp    1288 <main+0xb8>
xchg   %ax,%ax
add    $0x1,%ebp
cmp    $0xa,%ebp
je     12d6 <main+0x106>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   10c0 <sprintf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
mov    %r13,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
cmp    $0xffffffff,%eax
jne    1280 <main+0xb0>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    %eax,%edi
call   1050 <on_err@plt>
jmp    1280 <main+0xb0>
mov    %r12d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"inet_aton() failed\0A\00"
@.str.1 = [19 x i8] c"Sending packet %d\0A\00"
@.str.2 = [19 x i8] c"This is packet %d\0A\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
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 12, i32* %8
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = load i32, i32* @IPPROTO_UDP
%14 = call i32 @socket(i32 %11, i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @on_err(i32 %18)
br label %20
20: ; preds = %16, %2
%21 = bitcast %struct.sockaddr_in* %7 to i8*
%22 = call i32 @memset(i8* %21, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
%29 = call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%35 = call i64 @inet_aton(i8* %33, i32* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %20
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %20
store i32 0, i32* %10
br label %42
42: ; preds = %62, %41
%43 = load i32, i32* %10
%44 = icmp slt i32 %43, 10
br i1 %44, label %45, label %65
45: ; preds = %42
%46 = load i32, i32* %10
%47 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%49 = load i32, i32* %10
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %6
%52 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%53 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%54 = load i32, i32* %8
%55 = call i32 @sendto(i32 %51, i8* %52, i32 512, i32 0, %struct.sockaddr* %53, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %61
57: ; preds = %45
%58 = load i32, i32* @errno
%59 = call i32 @strerror(i32 %58)
%60 = call i32 @on_err(i32 %59)
br label %61
61: ; preds = %57, %45
br label %62
62: ; preds = %61
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %42
65: ; preds = %42
%66 = load i32, i32* %6
%67 = call i32 @close(i32 %66)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"inet_aton() failed\0A\00"
@.str.1 = [19 x i8] c"Sending packet %d\0A\00"
@.str.2 = [19 x i8] c"This is packet %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @IPPROTO_UDP
%10 = tail call i32 @socket(i32 %7, i32 %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @errno
%14 = tail call i32 @strerror(i32 %13)
%15 = tail call i32 @on_err(i32 %14)
br label %16
16: ; preds = %12, %2
%17 = call i32 @memset(i8* %5, i32 0, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = call i32 @htons(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%28 = call i64 @inet_aton(i8* %26, i32* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %16
%31 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %38
32: ; preds = %16
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %48
%37 = call i32 @close(i32 %10)
ret i32 0
38: ; preds = %30, %48
%39 = phi i32 [ 0, %30 ], [ %49, %48 ]
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%42 = call i32 @sendto(i32 %10, i8* %6, i32 512, i32 0, %struct.sockaddr* %31, i32 12)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %38
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 @on_err(i32 %46)
br label %48
48: ; preds = %38, %44
%49 = add nuw nsw i32 %39, 1
%50 = icmp eq i32 %49, 10
br i1 %50, label %36, label %38
}