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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_RAW;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
int sendto(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/,
           struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int SendPacket(char protocol[4], u_char *packet, int size, char *soAddr,
               char *dAddr, int port) {
  struct sockaddr_in saddr;
  int sock;
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = inet_addr(soAddr);
  if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
    fprintf(stderr, "+  %s packet error\n",
            (strcmp(protocol, "TCP") == 0)
                ? "TCP (SYN)"
                : ((strcmp(protocol, "RST") == 0) ? "TCP (RST)" : protocol));
    perror("   - Socket() ");
    pthread_exit(0);
  }
  if (sendto(sock, packet, size, 0, (struct sockaddr *)&saddr, sizeof(saddr)) ==
      -1) {
    fprintf(stderr, "+  %s packet error\n", protocol);
    perror("   - sendto() ");
    fprintf(stderr,
            "   + Debug\n    - Source Address: %s\n    - Destination Address: "
            "%s\n    - Port: %i\n",
            soAddr, dAddr, port);
    pthread_exit(0);
  }
  close(sock);
  return 1;
}


x86 assembly (clang, -O0):
<SendPacket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,-0x38(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0x0,%eax
jge    1296 <SendPacket+0x106>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1234 <SendPacket+0xa4>
lea    0xded(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    126e <SendPacket+0xde>
mov    -0x8(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    125e <SendPacket+0xce>
lea    0xdd1(%rip),%rax
mov    %rax,-0x50(%rbp)
jmp    1266 <SendPacket+0xd6>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x48(%rbp),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xda6(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
mov    -0x3c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    -0x38(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1040 <sendto@plt>
cmp    $0xffffffff,%eax
jne    130b <SendPacket+0x17b>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
lea    0xd63(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
lea    0xd51(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SendPacket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9d,%r12d
mov    %r8,0x20(%rsp)
mov    %rcx,%r13
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e30(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    %r9d,%edi
call   1030 <htons@plt>
mov    %eax,0x14(%rsp)
mov    %r13,%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x10(%rsp)
mov    0x0(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1230 <SendPacket+0xa0>
lea    0x10(%rsp),%r8
mov    %ebp,%edi
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1040 <sendto@plt>
cmp    $0xffffffff,%eax
je     125a <SendPacket+0xca>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0xdd0(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    12a7 <SendPacket+0x117>
lea    0xdc0(%rip),%rdx
jmp    12c4 <SendPacket+0x134>
mov    0x2d6f(%rip),%rbx
mov    (%rbx),%edi
lea    0xd96(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xdc4(%rip),%rdi
call   10a0 <perror@plt>
mov    (%rbx),%edi
lea    0xdc5(%rip),%rsi
mov    %r13,%rdx
mov    0x20(%rsp),%rcx
mov    %r12d,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
jmp    1215 <SendPacket+0x85>
lea    0xd74(%rip),%rsi
mov    %r15,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
lea    0xd66(%rip),%rdx
cmovne %r15,%rdx
lea    0xd35(%rip),%rsi
mov    0xc(%rsp),%edi
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    0xd53(%rip),%rdi
call   10a0 <perror@plt>
xor    %edi,%edi
call   1090 <pthread_exit@plt>
jmp    11f7 <SendPacket+0x67>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"+ %s packet error\0A\00"
@.str.1 = [4 x i8] c"TCP\00"
@.str.2 = [10 x i8] c"TCP (SYN)\00"
@.str.3 = [4 x i8] c"RST\00"
@.str.4 = [10 x i8] c"TCP (RST)\00"
@.str.5 = [15 x i8] c" - Socket() \00"
@.str.6 = [15 x i8] c" - sendto() \00"
@.str.7 = [82 x i8] c" + Debug\0A - Source Address: %s\0A - Destination Address: %s\0A - Port: %i\0A\00"
define i32 @SendPacket(i8* %0, i32* %1, i32 %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
store i8* %0, i8** %7
store i32* %1, i32** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 2
store i32 %15, i32* %16
%17 = load i32, i32* %12
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i8*, i8** %10
%21 = call i32 @inet_addr(i8* %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_RAW
%26 = load i32, i32* @IPPROTO_RAW
%27 = call i32 @socket(i32 %24, i32 %25, i32 %26)
store i32 %27, i32* %14
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %49
29: ; preds = %6
%30 = load i32, i32* @stderr
%31 = load i8*, i8** %7
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %44
35: ; preds = %29
%36 = load i8*, i8** %7
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %42
40: ; preds = %35
%41 = load i8*, i8** %7
br label %42
42: ; preds = %40, %39
%43 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), %39 ], [ %41, %40 ]
br label %44
44: ; preds = %42, %34
%45 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %34 ], [ %43, %42 ]
%46 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %45)
%47 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%48 = call i32 @pthread_exit(i32 0)
br label %49
49: ; preds = %44, %6
%50 = load i32, i32* %14
%51 = load i32*, i32** %8
%52 = load i32, i32* %9
%53 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%54 = call i32 @sendto(i32 %50, i32* %51, i32 %52, i32 0, %struct.sockaddr* %53, i32 12)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %67
56: ; preds = %49
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %7
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %58)
%60 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %10
%63 = load i8*, i8** %11
%64 = load i32, i32* %12
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.7, i64 0, i64 0), i8* %62, i8* %63, i32 %64)
%66 = call i32 @pthread_exit(i32 0)
br label %67
67: ; preds = %56, %49
%68 = load i32, i32* %14
%69 = call i32 @close(i32 %68)
ret i32 1
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_RAW = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"+ %s packet error\0A\00"
@.str.1 = [4 x i8] c"TCP\00"
@.str.2 = [10 x i8] c"TCP (SYN)\00"
@.str.3 = [4 x i8] c"RST\00"
@.str.4 = [10 x i8] c"TCP (RST)\00"
@.str.5 = [15 x i8] c" - Socket() \00"
@.str.6 = [15 x i8] c" - sendto() \00"
@.str.7 = [82 x i8] c" + Debug\0A - Source Address: %s\0A - Destination Address: %s\0A - Port: %i\0A\00"
define i32 @SendPacket(i8* %0, i32* %1, i32 %2, i8* %3, i8* %4, i32 %5) {
%7 = alloca %struct.sockaddr_in
%8 = bitcast %struct.sockaddr_in* %7 to i8*
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 %5)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
store i32 %11, i32* %12
%13 = tail call i32 @inet_addr(i8* %3)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_RAW
%17 = load i32, i32* @IPPROTO_RAW
%18 = tail call i32 @socket(i32 %15, i32 %16, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %33
20: ; preds = %6
%21 = load i32, i32* @stderr
%22 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %20
%25 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %0
br label %28
28: ; preds = %20, %24
%29 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %20 ]
%30 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%32 = tail call i32 @pthread_exit(i32 0)
br label %33
33: ; preds = %28, %6
%34 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%35 = call i32 @sendto(i32 %18, i32* %1, i32 %2, i32 0, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %0)
%40 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.7, i64 0, i64 0), i8* %3, i8* %4, i32 %5)
%43 = call i32 @pthread_exit(i32 0)
br label %44
44: ; preds = %37, %33
%45 = call i32 @close(i32 %18)
ret i32 1
}