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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_BROADCAST;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ htons(unsigned int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ nozombies();
int /*<<< orphan*/ perror(char *);
int sendto(int, char *, int /*<<< orphan*/, int /*<<< orphan*/,
           struct sockaddr *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void process(char *buf, ssize_t len, char *ip, unsigned int port,
             unsigned int sport, char *destination, unsigned int dport) {
  int sockfd;
  int broadcast = 1;
  struct sockaddr_in recvaddr;
  int numbytes;
  switch (fork()) {
  case -1:
    perror("fork() failed");
    break;
  case 0:
    nozombies();
    if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
      perror("sockfd");
      exit(1);
    }
    if ((setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &broadcast,
                    sizeof broadcast)) == -1) {
      perror("setsockopt - SO_SOCKET ");
      exit(1);
    }
    recvaddr.sin_family = AF_INET;
    recvaddr.sin_port = htons(dport);
    recvaddr.sin_addr.s_addr = inet_addr(destination);
    memset(recvaddr.sin_zero, '\0', sizeof recvaddr.sin_zero);
    numbytes = sendto(sockfd, buf, len, 0, (struct sockaddr *)&recvaddr,
                      sizeof recvaddr);
    close(sockfd);
    exit(1);
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
movl   $0x1,-0x30(%rbp)
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x48(%rbp)
sub    $0xffffffff,%eax
je     1202 <process+0x52>
jmp    11f2 <process+0x42>
mov    -0x48(%rbp),%eax
test   %eax,%eax
je     1213 <process+0x63>
jmp    12fa <process+0x14a>
lea    0xdf7(%rip),%rdi
call   10a0 <perror@plt>
jmp    12ff <process+0x14f>
mov    $0x0,%al
call   1030 <nozombies@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    1255 <process+0xa5>
lea    0xdc8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x2c(%rbp),%edi
mov    0x2d89(%rip),%rax
mov    (%rax),%esi
mov    0x2d68(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1298 <process+0xe8>
lea    0xd8c(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x10(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x40(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x2c(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    -0x40(%rbp),%r8
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12ff <process+0x14f>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %r9,%rbp
mov    %esi,%r14d
mov    %rdi,%r15
mov    0x50(%rsp),%ebx
movl   $0x1,0xc(%rsp)
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     11ee <process+0x3e>
test   %eax,%eax
je     1206 <process+0x56>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0b(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <perror@plt>
xor    %eax,%eax
call   1030 <nozombies@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    0x2dbb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1234 <process+0x84>
lea    0xddc(%rip),%rdi
jmp    1268 <process+0xb8>
mov    %eax,%r12d
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1277 <process+0xc7>
lea    0xdad(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,0x18(%rsp)
mov    %rbp,%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
lea    0x10(%rsp),%r8
mov    %r12d,%edi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
mov    $0x10,%r9d
call   1070 <sendto@plt>
mov    %r12d,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"fork() failed\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"sockfd\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [24 x i8] c"setsockopt - SO_SOCKET \00"
@AF_INET = global i32 0
define void @process(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sockaddr_in
%18 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32 %6, i32* %14
store i32 1, i32* %16
%19 = call i32 (...) @fork()
switch i32 %19, label %61 [
i32 -1, label %20
i32 0, label %22
]
20: ; preds = %7
%21 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %62
22: ; preds = %7
%23 = call i32 (...) @nozombies()
%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* %15
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %22
%29 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %22
%32 = load i32, i32* %15
%33 = load i32, i32* @SOL_SOCKET
%34 = load i32, i32* @SO_BROADCAST
%35 = call i32 @setsockopt(i32 %32, i32 %33, i32 %34, i32* %16, i32 4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %31
%38 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %31
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 3
store i32 %41, i32* %42
%43 = load i32, i32* %14
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %44, i32* %45
%46 = load i8*, i8** %13
%47 = call i32 @inet_addr(i8* %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @memset(i32 %51, i8 signext 0, i32 4)
%53 = load i32, i32* %15
%54 = load i8*, i8** %8
%55 = load i32, i32* %9
%56 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%57 = call i32 @sendto(i32 %53, i8* %54, i32 %55, i32 0, %struct.sockaddr* %56, i32 16)
store i32 %57, i32* %18
%58 = load i32, i32* %15
%59 = call i32 @close(i32 %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %7
br label %62
62: ; preds = %61, %20
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [14 x i8] c"fork() failed\00"
@PF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@.str.1 = [7 x i8] c"sockfd\00"
@SOL_SOCKET = global i32 0
@SO_BROADCAST = global i32 0
@.str.2 = [24 x i8] c"setsockopt - SO_SOCKET \00"
@AF_INET = global i32 0
define void @process(i8* %0, i32 %1, i8* nocapture readnone %2, i32 %3, i32 %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = bitcast i32* %8 to i8*
store i32 1, i32* %8
%11 = bitcast %struct.sockaddr_in* %9 to i8*
%12 = tail call i32 (...) @fork()
switch i32 %12, label %44 [
i32 -1, label %13
i32 0, label %15
]
13: ; preds = %7
%14 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %44
15: ; preds = %7
%16 = tail call i32 (...) @nozombies()
%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 %24
21: ; preds = %15
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_BROADCAST
%27 = call i32 @setsockopt(i32 %19, i32 %25, i32 %26, i32* %8, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %24
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 3
store i32 %33, i32* %34
%35 = call i32 @htons(i32 %6)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %35, i32* %36
%37 = call i32 @inet_addr(i8* %5)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1, i32 0
store i32 %37, i32* %38
%39 = call i32 @memset(i32 undef, i8 signext 0, i32 4)
%40 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%41 = call i32 @sendto(i32 %19, i8* %0, i32 %1, i32 0, %struct.sockaddr* %40, i32 16)
%42 = call i32 @close(i32 %19)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %7, %13
ret void
}