#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*/ PACKET_RX_RING;
scalar_t__ exit_packetsock(int, char *);
int init_packetsock(char **, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
char *process_rx(int, char *);
int /*<<< orphan*/ process_rx_release(char *);
int main(int argc, char **argv) {
  char *ring, *pkt;
  int fd;
  fd = init_packetsock(&ring, PACKET_RX_RING);
  if (fd < 0)
    return 1;
  pkt = process_rx(fd, ring);
  process_rx_release(ring);
  if (exit_packetsock(fd, ring))
    return 1;
  printf("OK\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1050 <init_packetsock@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1191 <main+0x41>
movl   $0x1,-0x4(%rbp)
jmp    11df <main+0x8f>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <process_rx@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <process_rx_release@plt>
mov    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <exit_packetsock@plt>
cmp    $0x0,%rax
je     11cc <main+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11df <main+0x8f>
lea    0xe2d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1050 <init_packetsock@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     11a1 <main+0x51>
mov    %eax,%ebp
mov    (%rsp),%rsi
mov    %eax,%edi
call   1060 <process_rx@plt>
mov    (%rsp),%rdi
call   1070 <process_rx_release@plt>
mov    (%rsp),%rsi
mov    %ebp,%edi
call   1040 <exit_packetsock@plt>
test   %rax,%rax
jne    11a1 <main+0x51>
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PACKET_RX_RING = global i32 0
@.str = [4 x i8] c"OK\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PACKET_RX_RING
%10 = call i32 @init_packetsock(i8** %6, i32 %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 1, i32* %3
br label %27
14: ; preds = %2
%15 = load i32, i32* %8
%16 = load i8*, i8** %6
%17 = call i8* @process_rx(i32 %15, i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %6
%19 = call i32 @process_rx_release(i8* %18)
%20 = load i32, i32* %8
%21 = load i8*, i8** %6
%22 = call i64 @exit_packetsock(i32 %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %14
store i32 1, i32* %3
br label %27
25: ; preds = %14
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %27
27: ; preds = %25, %24, %13
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@PACKET_RX_RING = global i32 0
@str = [3 x i8] c"OK\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = load i32, i32* @PACKET_RX_RING
%6 = call i32 @init_packetsock(i8** %3, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i8* @process_rx(i32 %6, i8* %9)
%11 = load i8*, i8** %3
%12 = call i32 @process_rx_release(i8* %11)
%13 = load i8*, i8** %3
%14 = call i64 @exit_packetsock(i32 %6, i8* %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %8, %2, %16
%19 = phi i32 [ 0, %16 ], [ 1, %2 ], [ 1, %8 ]
ret i32 %19
}