#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*/ IPPROTO_EGP;
int SOCK_DGRAM;
int SOCK_RAW;
int /*<<< orphan*/ SOL_IP;
scalar_t__ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ rx_one(int, int /*<<< orphan*/, int);
int socket_rx_ipv4(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void run_one_ipv4(int type) {
  int fd;
  fprintf(stderr, "ipv4 %s\n", type == SOCK_DGRAM ? "udp" : "raw");
  fd = socket_rx_ipv4(type, type == SOCK_RAW ? IPPROTO_EGP : 0);
  rx_one(fd, SOL_IP, 25);
  if (close(fd))
    error(1, errno, "close");
}


x86 assembly (clang, -O0):
<run_one_ipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%ecx
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    0xe96(%rip),%rdx
lea    0xe8b(%rip),%rax
cmp    %esi,%ecx
cmove  %rax,%rdx
lea    0xe75(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
jne    11b9 <run_one_ipv4+0x69>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
jmp    11c3 <run_one_ipv4+0x73>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    11c3 <run_one_ipv4+0x73>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1050 <socket_rx_ipv4@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
mov    $0x19,%edx
call   1030 <rx_one@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmp    $0x0,%rax
je     1213 <run_one_ipv4+0xc3>
mov    0x2db8(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe03(%rip),%rdx
call   1070 <error@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_one_ipv4>:
push   %rbx
mov    %edi,%ebx
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    0x2e6d(%rip),%rax
cmp    %ebx,(%rax)
lea    0xe9d(%rip),%rax
lea    0xe9a(%rip),%rdx
cmove  %rax,%rdx
lea    0xe82(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e4e(%rip),%rax
xor    %esi,%esi
cmp    %ebx,(%rax)
jne    1199 <run_one_ipv4+0x49>
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <socket_rx_ipv4@plt>
mov    %eax,%ebx
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0x19,%edx
call   1030 <rx_one@plt>
mov    %ebx,%edi
call   1040 <close@plt>
test   %rax,%rax
je     11de <run_one_ipv4+0x8e>
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdx
mov    $0x1,%edi
pop    %rbx
jmp    1070 <error@plt>
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"ipv4 %s\0A\00"
@SOCK_DGRAM = global i32 0
@.str.1 = [4 x i8] c"udp\00"
@.str.2 = [4 x i8] c"raw\00"
@SOCK_RAW = global i32 0
@IPPROTO_EGP = global i32 0
@SOL_IP = global i32 0
@errno = global i32 0
@.str.3 = [6 x i8] c"close\00"
define void @run_one_ipv4(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @stderr
%5 = load i32, i32* %2
%6 = load i32, i32* @SOCK_DGRAM
%7 = icmp eq i32 %5, %6
%8 = zext i1 %7 to i64
%9 = select i1 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%10 = call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* %2
%12 = load i32, i32* %2
%13 = load i32, i32* @SOCK_RAW
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %1
%16 = load i32, i32* @IPPROTO_EGP
br label %18
17: ; preds = %1
br label %18
18: ; preds = %17, %15
%19 = phi i32 [ %16, %15 ], [ 0, %17 ]
%20 = call i32 @socket_rx_ipv4(i32 %11, i32 %19)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = load i32, i32* @SOL_IP
%23 = call i32 @rx_one(i32 %21, i32 %22, i32 25)
%24 = load i32, i32* %3
%25 = call i64 @close(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %18
%28 = load i32, i32* @errno
%29 = call i32 @error(i32 1, i32 %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %18
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"ipv4 %s\0A\00"
@SOCK_DGRAM = global i32 0
@.str.1 = [4 x i8] c"udp\00"
@.str.2 = [4 x i8] c"raw\00"
@SOCK_RAW = global i32 0
@IPPROTO_EGP = global i32 0
@SOL_IP = global i32 0
@errno = global i32 0
@.str.3 = [6 x i8] c"close\00"
define void @run_one_ipv4(i32 %0) {
%2 = load i32, i32* @stderr
%3 = load i32, i32* @SOCK_DGRAM
%4 = icmp eq i32 %3, %0
%5 = select i1 %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%6 = tail call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i32, i32* @SOCK_RAW
%8 = icmp eq i32 %7, %0
%9 = load i32, i32* @IPPROTO_EGP
%10 = select i1 %8, i32 %9, i32 0
%11 = tail call i32 @socket_rx_ipv4(i32 %0, i32 %10)
%12 = load i32, i32* @SOL_IP
%13 = tail call i32 @rx_one(i32 %11, i32 %12, i32 25)
%14 = tail call i64 @close(i32 %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i32, i32* @errno
%18 = tail call i32 @error(i32 1, i32 %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %16, %1
ret void
}