#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 */
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ dump(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int i, recv_length, sockfd;
  u_char buffer[9000];
  if ((sockfd = socket(PF_INET, SOCK_RAW, IPPROTO_TCP)) == -1)
    fatal("in socket");
  printf("welcome to FrozenBox tools - RAW sniffer\nfor more info visit "
         "www.frozenbox.org\n\n\t sniffing....\n\n");
  do {
    recv_length = recv(sockfd, buffer, 8000, 0);
    printf("\n\tGot a %d byte packet\n", recv_length);
    dump(buffer, recv_length);
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8cb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    119a <main+0x4a>
lea    0xe6b(%rip),%rdi
call   1060 <fatal@plt>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%edi
lea    -0x8cb0(%rbp),%rsi
mov    $0x1f40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8cb0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <dump@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11a8 <main+0x58>
jmp    11f0 <main+0xa0>
mov    -0x4(%rbp),%eax
add    $0x8cb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x8ca8,%rsp
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    11a1 <main+0x41>
lea    0xe64(%rip),%rdi
call   1070 <fatal@plt>
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rbx
lea    0xe53(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1f40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <dump@plt>
jmp    11c0 <main+0x60>

LLVM IR (-O0):
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [10 x i8] c"in socket\00"
@.str.1 = [97 x i8] c"welcome to FrozenBox tools - RAW sniffer\0Afor more info visit www.frozenbox.org\0A\0A\09 sniffing....\0A\0A\00"
@.str.2 = [24 x i8] c"\0A\09Got a %d byte packet\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [9000 x i32]
store i32 0, i32* %1
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_RAW
%8 = load i32, i32* @IPPROTO_TCP
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %24, %13
%16 = load i32, i32* %4
%17 = getelementptr inbounds [9000 x i32], [9000 x i32]* %5, i64 0, i64 0
%18 = call i32 @recv(i32 %16, i32* %17, i32 8000, i32 0)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [9000 x i32], [9000 x i32]* %5, i64 0, i64 0
%22 = load i32, i32* %3
%23 = call i32 @dump(i32* %21, i32 %22)
br label %24
24: ; preds = %15
br i1 true, label %15, label %25
25: ; preds = %24
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@PF_INET = global i32 0
@SOCK_RAW = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [10 x i8] c"in socket\00"
@.str.2 = [24 x i8] c"\0A\09Got a %d byte packet\0A\00"
@str = [96 x i8] c"welcome to FrozenBox tools - RAW sniffer\0Afor more info visit www.frozenbox.org\0A\0A\09 sniffing....\0A\00"
define i32 @main() {
%1 = alloca [9000 x i32]
%2 = bitcast [9000 x i32]* %1 to i8*
%3 = load i32, i32* @PF_INET
%4 = load i32, i32* @SOCK_RAW
%5 = load i32, i32* @IPPROTO_TCP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @fatal(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @str, i64 0, i64 0))
%12 = getelementptr inbounds [9000 x i32], [9000 x i32]* %1, i64 0, i64 0
br label %13
13: ; preds = %13, %10
%14 = call i32 @recv(i32 %6, i32* %12, i32 8000, i32 0)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = call i32 @dump(i32* %12, i32 %14)
br label %13
}