#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *my_file;
  int result;
  if (argc < 3) {
    fprintf(stderr, "Usage: process id, ppout specific\n");
    return 0;
  }
  int sock, length;
  socklen_t tolen;
  struct sockaddr_in server;
  struct sockaddr_in to;
  struct hostent *hp;
  FILE *myfile;
  if (argc < 3) {
    fprintf(stderr, "Usage: process id, ppout specific\n");
    return 0;
  }
  sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (sock < 0)
    error("ERROR opening socket");
  length = sizeof(server);
  bzero(&server, length);
  to.sin_family = AF_INET;
  hp = gethostbyname("192.168.1.1");
  if (hp == 0)
    error("Unknown host");
  bcopy((char *)hp->h_addr, (char *)&to.sin_addr, hp->h_length);
  to.sin_port = htons(atoi("12345"));
  tolen = sizeof(struct sockaddr_in);
  char addr_specs_a[256];
  sprintf(addr_specs_a, "/proc/%s/hw/ioreg/%s_a", argv[1], argv[2]);
  char my_buffer[1024];
  int ii;
  printf("This program does a sendto 1,000,000 times.\n");
  my_file = fopen(addr_specs_a, "r");
  result = fread(my_buffer, 1, 1024, my_file);
  fclose(my_file);
  int n;
  for (ii = 0; ii < 1000000; ii++) {
    n = sendto(sock, my_buffer, 1024, 0, (struct sockaddr *)&to, tolen);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x570,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1224 <main+0x44>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c4 <main+0x1e4>
cmpl   $0x3,-0x8(%rbp)
jge    124f <main+0x6f>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xdc2(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c4 <main+0x1e4>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    0x2d81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1281 <main+0xa1>
lea    0xda7(%rip),%rdi
call   10b0 <error@plt>
movl   $0xc,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    -0x38(%rbp),%rdi
call   10d0 <bzero@plt>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
lea    0xd91(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12c7 <main+0xe7>
lea    0xd82(%rip),%rdi
call   10b0 <error@plt>
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x48(%rbp),%rsi
add    $0x4,%rsi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bcopy@plt>
lea    0xd68(%rip),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x48(%rbp)
movl   $0xc,-0x28(%rbp)
lea    -0x160(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xd3a(%rip),%rsi
call   10f0 <sprintf@plt>
lea    0xd45(%rip),%rdi
call   1060 <printf@plt>
lea    -0x160(%rbp),%rdi
lea    0xd5f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x560(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x564(%rbp)
cmpl   $0xf4240,-0x564(%rbp)
jge    13bd <main+0x1dd>
mov    -0x20(%rbp),%edi
lea    -0x560(%rbp),%rsi
lea    -0x48(%rbp),%r8
mov    -0x28(%rbp),%r9d
mov    $0x400,%edx
xor    %ecx,%ecx
call   1070 <sendto@plt>
mov    %eax,-0x568(%rbp)
mov    -0x564(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x564(%rbp)
jmp    1375 <main+0x195>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x570,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x518,%rsp
cmp    $0x2,%edi
jg     11ec <main+0x2c>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12f0 <main+0x130>
mov    %rsi,%r14
mov    0x2df2(%rip),%rbx
mov    (%rbx),%edi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    121b <main+0x5b>
lea    0xe0d(%rip),%rdi
call   10b0 <error@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe10(%rip),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1241 <main+0x81>
lea    0xe08(%rip),%rdi
call   10b0 <error@plt>
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdi
mov    (%rbx),%edx
call   10a0 <memmove@plt>
mov    $0x3039,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    0x8(%r14),%rdx
mov    0x10(%r14),%rcx
lea    0xde4(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   10d0 <sprintf@plt>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
lea    0xddb(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbp
lea    0x110(%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    $0xf4240,%ebx
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
mov    %rbp,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
add    $0xffffffff,%ebx
jne    12d0 <main+0x110>
xor    %eax,%eax
add    $0x518,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Usage: process id, ppout specific\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [12 x i8] c"192.168.1.1\00"
@.str.3 = [13 x i8] c"Unknown host\00"
@.str.4 = [6 x i8] c"12345\00"
@.str.5 = [23 x i8] c"/proc/%s/hw/ioreg/%s_a\00"
@.str.6 = [45 x i8] c"This program does a sendto 1,000,000 times.\0A\00"
@.str.7 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
%14 = alloca i32*
%15 = alloca [256 x i8]
%16 = alloca [1024 x i8]
%17 = alloca i32
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %91
24: ; preds = %2
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %91
30: ; preds = %24
%31 = load i32, i32* @AF_INET
%32 = load i32, i32* @SOCK_DGRAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
store i32 12, i32* %9
%39 = load i32, i32* %9
%40 = call i32 @bzero(%struct.sockaddr_in* %11, i32 %39)
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %41, i32* %42
%43 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %43, %struct.hostent** %13
%44 = load %struct.hostent*, %struct.hostent** %13
%45 = icmp eq %struct.hostent* %44, null
br i1 %45, label %46, label %48
46: ; preds = %38
%47 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %38
%49 = load %struct.hostent*, %struct.hostent** %13
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 1
%51 = load i64, i64* %50
%52 = inttoptr i64 %51 to i8*
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%54 = bitcast i32* %53 to i8*
%55 = load %struct.hostent*, %struct.hostent** %13
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @bcopy(i8* %52, i8* %54, i32 %57)
%59 = call i32 @atoi(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%60 = call i32 @htons(i32 %59)
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %60, i32* %61
store i32 12, i32* %10
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 1
%65 = load i8*, i8** %64
%66 = load i8**, i8*** %5
%67 = getelementptr inbounds i8*, i8** %66, i64 2
%68 = load i8*, i8** %67
%69 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %65, i8* %68)
%70 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.6, i64 0, i64 0))
%71 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%72 = call i32* @fopen(i8* %71, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %72, i32** %6
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%74 = load i32*, i32** %6
%75 = call i32 @fread(i8* %73, i32 1, i32 1024, i32* %74)
store i32 %75, i32* %7
%76 = load i32*, i32** %6
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %17
br label %78
78: ; preds = %87, %48
%79 = load i32, i32* %17
%80 = icmp slt i32 %79, 1000000
br i1 %80, label %81, label %90
81: ; preds = %78
%82 = load i32, i32* %8
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%84 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%85 = load i32, i32* %10
%86 = call i32 @sendto(i32 %82, i8* %83, i32 1024, i32 0, %struct.sockaddr* %84, i32 %85)
store i32 %86, i32* %18
br label %87
87: ; preds = %81
%88 = load i32, i32* %17
%89 = add nsw i32 %88, 1
store i32 %89, i32* %17
br label %78
90: ; preds = %78
store i32 0, i32* %3
br label %91
91: ; preds = %90, %27, %21
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Usage: process id, ppout specific\0A\00"
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [12 x i8] c"192.168.1.1\00"
@.str.3 = [13 x i8] c"Unknown host\00"
@.str.5 = [23 x i8] c"/proc/%s/hw/ioreg/%s_a\00"
@.str.7 = [2 x i8] c"r\00"
@str = [44 x i8] c"This program does a sendto 1,000,000 times.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [256 x i8]
%5 = alloca [1024 x i8]
%6 = icmp slt i32 %0, 3
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
br label %53
10: ; preds = %2
%11 = bitcast %struct.sockaddr_in* %3 to i8*
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_DGRAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %19, i32* %20
%21 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 1
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to i8*
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%30 = bitcast i32* %29 to i8*
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %21, i64 0, i32 0
%32 = load i32, i32* %31
%33 = tail call i32 @htons(i32 12345)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %33, i32* %34
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8*, i8** %1, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i8* %37, i8* %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%43 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%44 = call i32 @fread(i8* %41, i32 1, i32 1024, i32* %43)
%45 = tail call i32 @fclose(i32* %43)
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
br label %47
47: ; preds = %25, %47
%48 = phi i32 [ 0, %25 ], [ %50, %47 ]
%49 = call i32 @sendto(i32 %14, i8* %41, i32 1024, i32 0, %struct.sockaddr* %46, i32 12)
%50 = add nuw nsw i32 %48, 1
%51 = icmp eq i32 %50, 1000000
br i1 %51, label %52, label %47
52: ; preds = %47
br label %53
53: ; preds = %52, %7
ret i32 0
}