#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);
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");
  for (i = 0; i < 3; i++) {
    recv_length = recv(sockfd, buffer, 8000, 0);
    printf("Got a %d byte packet\n", recv_length);
    dump(buffer, recv_length);
  }
}


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>
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11f0 <main+0xa0>
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    0xe3c(%rip),%rdi
call   1040 <printf@plt>
lea    -0x8cb0(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <dump@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a1 <main+0x51>
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    0x2e6c(%rip),%rax
mov    (%rax),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1190 <main+0x40>
lea    0xe75(%rip),%rdi
call   1060 <fatal@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
lea    0xe5d(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <dump@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <dump@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1f40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1050 <dump@plt>
xor    %eax,%eax
add    $0x8ca8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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 = [22 x i8] c"Got 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
store i32 0, i32* %2
br label %14
14: ; preds = %26, %13
%15 = load i32, i32* %2
%16 = icmp slt i32 %15, 3
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load i32, i32* %4
%19 = getelementptr inbounds [9000 x i32], [9000 x i32]* %5, i64 0, i64 0
%20 = call i32 @recv(i32 %18, i32* %19, i32 8000, i32 0)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [9000 x i32], [9000 x i32]* %5, i64 0, i64 0
%24 = load i32, i32* %3
%25 = call i32 @dump(i32* %23, i32 %24)
br label %26
26: ; preds = %17
%27 = load i32, i32* %2
%28 = add nsw i32 %27, 1
store i32 %28, i32* %2
br label %14
29: ; preds = %14
%30 = load i32, i32* %1
ret i32 %30
}

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.1 = [22 x i8] c"Got a %d byte packet\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 = getelementptr inbounds [9000 x i32], [9000 x i32]* %1, i64 0, i64 0
%12 = call i32 @recv(i32 %6, i32* %11, i32 8000, i32 0)
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = call i32 @dump(i32* %11, i32 %12)
%15 = call i32 @recv(i32 %6, i32* %11, i32 8000, i32 0)
%16 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i32 @dump(i32* %11, i32 %15)
%18 = call i32 @recv(i32 %6, i32* %11, i32 8000, i32 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @dump(i32* %11, i32 %18)
ret i32 0
}