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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1060 <init_packetsock@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jge    118a <main+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    11da <main+0x9a>
mov    -0x84(%rbp),%edi
mov    -0x18(%rbp),%rsi
lea    -0x80(%rbp),%rdx
mov    $0x64,%ecx
call   1030 <process_tx@plt>
mov    -0x84(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <exit_packetsock@plt>
cmp    $0x0,%rax
je     11c7 <main+0x87>
movl   $0x1,-0x4(%rbp)
jmp    11da <main+0x9a>
lea    0xe32(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1060 <init_packetsock@plt>
mov    $0x1,%ebx
test   %eax,%eax
js     1199 <main+0x59>
mov    %eax,%ebp
mov    0x8(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %eax,%edi
mov    $0x64,%ecx
call   1030 <process_tx@plt>
mov    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1050 <exit_packetsock@plt>
test   %rax,%rax
jne    1199 <main+0x59>
lea    0xe6e(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@PACKET_TX_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 [100 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PACKET_TX_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 %26
14: ; preds = %2
%15 = load i32, i32* %8
%16 = load i8*, i8** %6
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%18 = call i32 @process_tx(i32 %15, i8* %16, i8* %17, i32 100)
%19 = load i32, i32* %8
%20 = load i8*, i8** %6
%21 = call i64 @exit_packetsock(i32 %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %14
store i32 1, i32* %3
br label %26
24: ; preds = %14
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %26
26: ; preds = %24, %23, %13
%27 = load i32, i32* %3
ret i32 %27
}

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