#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ dump_packet_info4(char *, int);
int /*<<< orphan*/ dump_packet_info6(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ is_packet_for_us4(char *, int);
scalar_t__ is_packet_for_us6(char *, int);
int /*<<< orphan*/ perror(char *);
int recv(int, char *, int, int /*<<< orphan*/);
void loop_on_receive(int icmp_socket, int ip_version) {
  int packet_size;
  char packet[9000];
  while (true) {
    packet_size = recv(icmp_socket, packet, 9000, 0);
    if (packet_size < -1) {
      perror("Failure during receive");
      exit(EXIT_FAILURE);
    }
    if (ip_version == 6) {
      if (is_packet_for_us6(packet, packet_size)) {
        dump_packet_info6(packet, packet_size);
        return;
      }
    } else {
      if (is_packet_for_us4(packet, packet_size)) {
        dump_packet_info4(packet, packet_size);
        return;
      }
    }
  }
}


x86 assembly (clang, -O0):
<loop_on_receive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2340,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2340(%rbp),%rsi
mov    $0x2328,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jge    11be <loop_on_receive+0x4e>
lea    0xe55(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x6,-0x8(%rbp)
jne    11fa <loop_on_receive+0x8a>
lea    -0x2340(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <is_packet_for_us6@plt>
cmp    $0x0,%rax
je     11f5 <loop_on_receive+0x85>
lea    -0x2340(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1090 <dump_packet_info6@plt>
jmp    1231 <loop_on_receive+0xc1>
jmp    122c <loop_on_receive+0xbc>
lea    -0x2340(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <is_packet_for_us4@plt>
cmp    $0x0,%rax
je     1227 <loop_on_receive+0xb7>
lea    -0x2340(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <dump_packet_info4@plt>
jmp    1231 <loop_on_receive+0xc1>
jmp    122c <loop_on_receive+0xbc>
jmp    1181 <loop_on_receive+0x11>
add    $0x2340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop_on_receive>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2328,%rsp
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rsp,%rsi
mov    $0x2328,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0xffffffff,%eax
jl     11fc <loop_on_receive+0x8c>
mov    %eax,%ebx
mov    %rsp,%rbp
jmp    11c3 <loop_on_receive+0x53>
xchg   %ax,%ax
call   1050 <is_packet_for_us4@plt>
test   %rax,%rax
jne    11e4 <loop_on_receive+0x74>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x2328,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jl     11fc <loop_on_receive+0x8c>
mov    %rbp,%rdi
mov    %ebx,%esi
cmp    $0x6,%r14d
jne    11a0 <loop_on_receive+0x30>
call   1040 <is_packet_for_us6@plt>
test   %rax,%rax
je     11aa <loop_on_receive+0x3a>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1090 <dump_packet_info6@plt>
jmp    11ee <loop_on_receive+0x7e>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1080 <dump_packet_info4@plt>
add    $0x2328,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfd(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Failure during receive\00"
@EXIT_FAILURE = global i32 0
define void @loop_on_receive(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [9000 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %7
7: ; preds = %2, %40
%8 = load i32, i32* %3
%9 = getelementptr inbounds [9000 x i8], [9000 x i8]* %6, i64 0, i64 0
%10 = call i32 @recv(i32 %8, i8* %9, i32 9000, i32 0)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %7
%14 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %7
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 6
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = getelementptr inbounds [9000 x i8], [9000 x i8]* %6, i64 0, i64 0
%22 = load i32, i32* %5
%23 = call i64 @is_packet_for_us6(i8* %21, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = getelementptr inbounds [9000 x i8], [9000 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* %5
%28 = call i32 @dump_packet_info6(i8* %26, i32 %27)
br label %41
29: ; preds = %20
br label %40
30: ; preds = %17
%31 = getelementptr inbounds [9000 x i8], [9000 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %5
%33 = call i64 @is_packet_for_us4(i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = getelementptr inbounds [9000 x i8], [9000 x i8]* %6, i64 0, i64 0
%37 = load i32, i32* %5
%38 = call i32 @dump_packet_info4(i8* %36, i32 %37)
br label %41
39: ; preds = %30
br label %40
40: ; preds = %39, %29
br label %7
41: ; preds = %35, %25
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Failure during receive\00"
@EXIT_FAILURE = global i32 0
define void @loop_on_receive(i32 %0, i32 %1) {
%3 = alloca [9000 x i8]
%4 = getelementptr inbounds [9000 x i8], [9000 x i8]* %3, i64 0, i64 0
%5 = call i32 @recv(i32 %0, i8* %4, i32 9000, i32 0)
%6 = icmp slt i32 %5, -1
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = icmp eq i32 %1, 6
br label %13
9: ; preds = %25, %2
%10 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %7, %25
%14 = phi i32 [ %5, %7 ], [ %26, %25 ]
br i1 %8, label %15, label %20
15: ; preds = %13
%16 = call i64 @is_packet_for_us6(i8* %4, i32 %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %15
%19 = call i32 @dump_packet_info6(i8* %4, i32 %14)
br label %28
20: ; preds = %13
%21 = call i64 @is_packet_for_us4(i8* %4, i32 %14)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @dump_packet_info4(i8* %4, i32 %14)
br label %28
25: ; preds = %20, %15
%26 = call i32 @recv(i32 %0, i8* %4, i32 9000, i32 0)
%27 = icmp slt i32 %26, -1
br i1 %27, label %9, label %13
28: ; preds = %23, %18
ret void
}