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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
scalar_t__ sendto(int, char *, scalar_t__, int /*<<< orphan*/,
                  struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int main(int argc, char *argv[]) {
  struct sockaddr_in srv;
  int sockfd;
  char buffer[(1024)];
  int i;
  int n;
  if (argc < 2) {
    fprintf(stdout, "Usage: %s <IP address of server>\n", argv[0]);
    return -1;
  }
  sockfd = socket(PF_INET, SOCK_DGRAM, 0);
  if (sockfd < 0) {
    fprintf(stderr, "Failed to create socket file!\n");
    return -2;
  }
  memset(&srv, 0, sizeof(srv));
  srv.sin_family = AF_INET;
  srv.sin_addr.s_addr = inet_addr(argv[1]);
  srv.sin_port = (0x431);
  for (i = 0; i != 1024; ++i) {
    sprintf(buffer, "Packet %x\n", i);
    fprintf(stdout, "Sending %s ...\n", buffer);
    if (sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr *)&srv,
               sizeof(srv)) != strlen(buffer)) {
      fprintf(stderr, "Failed to send packet %x!\n", i);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bd <main+0x4d>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1331 <main+0x1c1>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1206 <main+0x96>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1331 <main+0x1c1>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x431,-0x20(%rbp)
movl   $0x0,-0x434(%rbp)
cmpl   $0x400,-0x434(%rbp)
je     132a <main+0x1ba>
lea    -0x430(%rbp),%rdi
mov    -0x434(%rbp),%edx
lea    0xdda(%rip),%rsi
call   1080 <sprintf@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44c(%rbp)
lea    -0x430(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x44c(%rbp),%edi
mov    -0x448(%rbp),%rsi
mov    %rax,%rdx
lea    -0x20(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %rax,-0x440(%rbp)
lea    -0x430(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x440(%rbp),%rax
cmp    %rcx,%rax
je     1311 <main+0x1a1>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
mov    -0x434(%rbp),%edx
lea    0xd52(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1316 <main+0x1a6>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1243 <main+0xd3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11ad <main+0x3d>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe64(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    12bb <main+0x14b>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
test   %eax,%eax
js     129f <main+0x12f>
mov    %eax,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rsp)
movl   $0x431,(%rsp)
lea    0x10(%rsp),%rbx
mov    0x2db4(%rip),%r15
lea    0xe39(%rip),%r12
xor    %r13d,%r13d
jmp    122d <main+0xbd>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13d
cmp    $0x400,%r13d
je     129b <main+0x12b>
mov    %rbx,%rdi
lea    0xe0a(%rip),%rsi
mov    %r13d,%edx
call   1080 <sprintf@plt>
mov    (%r15),%edi
mov    %r12,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
mov    %rsp,%r8
mov    $0xc,%r9d
call   1050 <sendto@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%r14
je     1220 <main+0xb0>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1220 <main+0xb0>
xor    %eax,%eax
jmp    12bb <main+0x14b>
mov    0x2d2a(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@.str = [34 x i8] c"Usage: %s <IP address of server>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Failed to create socket file!\0A\00"
@AF_INET = global i32 0
@.str.2 = [11 x i8] c"Packet %x\0A\00"
@.str.3 = [16 x i8] c"Sending %s ...\0A\00"
@.str.4 = [27 x i8] c"Failed to send packet %x!\0A\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 [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %3
br label %67
19: ; preds = %2
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_DGRAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %3
br label %67
28: ; preds = %19
%29 = call i32 @memset(%struct.sockaddr_in* %6, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @inet_addr(i8* %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %35, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 1073, i32* %38
store i32 0, i32* %9
br label %39
39: ; preds = %63, %28
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 1024
br i1 %41, label %42, label %66
42: ; preds = %39
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%44 = load i32, i32* %9
%45 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %44)
%46 = load i32, i32* @stdout
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %7
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = call i64 @strlen(i8* %51)
%53 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%54 = call i64 @sendto(i32 %49, i8* %50, i64 %52, i32 0, %struct.sockaddr* %53, i32 12)
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%56 = call i64 @strlen(i8* %55)
%57 = icmp ne i64 %54, %56
br i1 %57, label %58, label %62
58: ; preds = %42
%59 = load i32, i32* @stderr
%60 = load i32, i32* %9
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %58, %42
br label %63
63: ; preds = %62
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %39
66: ; preds = %39
store i32 0, i32* %3
br label %67
67: ; preds = %66, %25, %13
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stdout = global i32 0
@.str = [34 x i8] c"Usage: %s <IP address of server>\0A\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Failed to create socket file!\0A\00"
@AF_INET = global i32 0
@.str.2 = [11 x i8] c"Packet %x\0A\00"
@.str.3 = [16 x i8] c"Sending %s ...\0A\00"
@.str.4 = [27 x i8] c"Failed to send packet %x!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stdout
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %45
12: ; preds = %2
%13 = load i32, i32* @PF_INET
%14 = load i32, i32* @SOCK_DGRAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %45
20: ; preds = %12
%21 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %22, i32* %23
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @inet_addr(i8* %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 1073, i32* %28
%29 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %30
30: ; preds = %20, %42
%31 = phi i32 [ 0, %20 ], [ %43, %42 ]
%32 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = load i32, i32* @stdout
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%35 = call i64 @strlen(i8* %6)
%36 = call i64 @sendto(i32 %15, i8* %6, i64 %35, i32 0, %struct.sockaddr* %29, i32 12)
%37 = call i64 @strlen(i8* %6)
%38 = icmp eq i64 %36, %37
br i1 %38, label %42, label %39
39: ; preds = %30
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %42
42: ; preds = %30, %39
%43 = add nuw nsw i32 %31, 1
%44 = icmp eq i32 %43, 1024
br i1 %44, label %45, label %30
45: ; preds = %42, %17, %8
%46 = phi i32 [ -1, %8 ], [ -2, %17 ], [ 0, %42 ]
ret i32 %46
}