#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ print_nice_policy_line(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strncasecmp(char *, char *, int);
int list_policies() {
  FILE *file = fopen("/proc/virtmod/policy/policy_v4", "r");
  if (!file) {
    fprintf(stderr, "Failed to open policy table, is virtNet module loaded?\n");
    return 1;
  }
  char buffer[BUFSIZ];
  printf("EGRESS policy table\n");
  printf("source             destination        prot sport dport actn  "
         "linkselect packets      bytes\n");
  while (!feof(file)) {
    fgets(buffer, sizeof(buffer), file);
    if (strncasecmp(buffer, "egress", 6) == 0) {
      continue;
    } else if (strncasecmp(buffer, "source", 6) == 0) {
      continue;
    } else if (strncasecmp(buffer, "ingress", 7) == 0) {
      break;
    }
    print_nice_policy_line(buffer);
  }
  printf("\n");
  printf("INGRESS policy table\n");
  printf("source             destination        prot sport dport actn  "
         "linkselect packets      bytes\n");
  while (!feof(file)) {
    fgets(buffer, sizeof(buffer), file);
    if (strncasecmp(buffer, "source", 6) == 0) {
      continue;
    }
    print_nice_policy_line(buffer);
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<list_policies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe71(%rip),%rdi
lea    0xe89(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <list_policies+0x4b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1366 <list_policies+0x1e6>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x30(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1231 <list_policies+0xb1>
jmp    12c8 <list_policies+0x148>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x28(%rbp),%rdi
lea    0xe7b(%rip),%rsi
mov    $0x6,%edx
call   1090 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1268 <list_policies+0xe8>
jmp    1213 <list_policies+0x93>
mov    -0x28(%rbp),%rdi
lea    0xe5e(%rip),%rsi
mov    $0x6,%edx
call   1090 <strncasecmp@plt>
cmp    $0x0,%rax
jne    128c <list_policies+0x10c>
jmp    1213 <list_policies+0x93>
mov    -0x28(%rbp),%rdi
lea    0xe41(%rip),%rsi
mov    $0x7,%edx
call   1090 <strncasecmp@plt>
cmp    $0x0,%rax
jne    12b0 <list_policies+0x130>
jmp    12c8 <list_policies+0x148>
jmp    12b5 <list_policies+0x135>
jmp    12ba <list_policies+0x13a>
mov    -0x28(%rbp),%rdi
call   1030 <print_nice_policy_line@plt>
jmp    1213 <list_policies+0x93>
lea    0xd88(%rip),%rdi
call   1050 <printf@plt>
lea    0xe05(%rip),%rdi
call   1050 <printf@plt>
lea    0xd87(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    130a <list_policies+0x18a>
jmp    134f <list_policies+0x1cf>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
call   1060 <fgets@plt>
mov    -0x28(%rbp),%rdi
lea    0xda9(%rip),%rsi
mov    $0x6,%edx
call   1090 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1341 <list_policies+0x1c1>
jmp    12ec <list_policies+0x16c>
mov    -0x28(%rbp),%rdi
call   1030 <print_nice_policy_line@plt>
jmp    12ec <list_policies+0x16c>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_policies>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5b(%rip),%rdi
lea    0xe73(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1245 <list_policies+0xb5>
mov    %rax,%r15
mov    %rsp,-0x30(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
lea    0xea6(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     126e <list_policies+0xde>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe78(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     12ee <list_policies+0x15e>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
mov    -0x30(%rbp),%rsp
jmp    125f <list_policies+0xcf>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde4(%rip),%r12
lea    0xde4(%rip),%r13
jmp    1298 <list_policies+0x108>
xchg   %ax,%ax
mov    %rbx,%rdi
call   1050 <print_nice_policy_line@plt>
mov    %r15,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1203 <list_policies+0x73>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x6,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
je     1288 <list_policies+0xf8>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x6,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
je     1288 <list_policies+0xf8>
mov    %rbx,%rdi
lea    0xd8d(%rip),%rsi
mov    $0x7,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
jne    1280 <list_policies+0xf0>
jmp    1203 <list_policies+0x73>
lea    0xd6b(%rip),%r12
jmp    1310 <list_policies+0x180>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1235 <list_policies+0xa5>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x6,%edx
call   10a0 <strncasecmp@plt>
test   %rax,%rax
je     1300 <list_policies+0x170>
mov    %rbx,%rdi
call   1050 <print_nice_policy_line@plt>
jmp    1300 <list_policies+0x170>

LLVM IR (-O0):
@.str = [31 x i8] c"/proc/virtmod/policy/policy_v4\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Failed to open policy table, is virtNet module loaded?\0A\00"
@BUFSIZ = global i32 0
@.str.3 = [21 x i8] c"EGRESS policy table\0A\00"
@.str.4 = [92 x i8] c"source destination prot sport dport actn linkselect packets bytes\0A\00"
@.str.5 = [7 x i8] c"egress\00"
@.str.6 = [7 x i8] c"source\00"
@.str.7 = [8 x i8] c"ingress\00"
@.str.8 = [2 x i8] c"\0A\00"
@.str.9 = [22 x i8] c"INGRESS policy table\0A\00"
define i32 @list_policies() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %64
11: ; preds = %0
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i8, i64 %13
store i64 %13, i64* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0))
br label %18
18: ; preds = %40, %33, %29, %11
%19 = load i32*, i32** %2
%20 = call i32 @feof(i32* %19)
%21 = icmp ne i32 %20, 0
%22 = xor i1 %21, true
br i1 %22, label %23, label %42
23: ; preds = %18
%24 = trunc i64 %13 to i32
%25 = load i32*, i32** %2
%26 = call i32 @fgets(i8* %15, i32 %24, i32* %25)
%27 = call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 6)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
br label %18
30: ; preds = %23
%31 = call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %30
br label %18
34: ; preds = %30
%35 = call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 7)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
br label %42
38: ; preds = %34
br label %39
39: ; preds = %38
br label %40
40: ; preds = %39
%41 = call i32 @print_nice_policy_line(i8* %15)
br label %18
42: ; preds = %37, %18
%43 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%44 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%45 = call i32 @printf(i8* getelementptr inbounds ([92 x i8], [92 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %58, %57, %42
%47 = load i32*, i32** %2
%48 = call i32 @feof(i32* %47)
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
br i1 %50, label %51, label %60
51: ; preds = %46
%52 = trunc i64 %13 to i32
%53 = load i32*, i32** %2
%54 = call i32 @fgets(i8* %15, i32 %52, i32* %53)
%55 = call i64 @strncasecmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %51
br label %46
58: ; preds = %51
%59 = call i32 @print_nice_policy_line(i8* %15)
br label %46
60: ; preds = %46
%61 = load i32*, i32** %2
%62 = call i32 @fclose(i32* %61)
store i32 0, i32* %1
%63 = load i8*, i8** %3
br label %64
64: ; preds = %60, %8
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str = [31 x i8] c"/proc/virtmod/policy/policy_v4\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [56 x i8] c"Failed to open policy table, is virtNet module loaded?\0A\00"
@BUFSIZ = global i32 0
@.str.5 = [7 x i8] c"egress\00"
@.str.6 = [7 x i8] c"source\00"
@.str.7 = [8 x i8] c"ingress\00"
@str = [20 x i8] c"EGRESS policy table\00"
@str.11 = [21 x i8] c"INGRESS policy table\00"
@str.12 = [91 x i8] c"source destination prot sport dport actn linkselect packets bytes\00"
define i32 @list_policies() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
br label %47
6: ; preds = %0
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @str.12, i64 0, i64 0))
%13 = call i32 @feof(i32* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %30
15: ; preds = %6, %27
%16 = call i32 @fgets(i8* %10, i32 %7, i32* %1)
%17 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 6)
%18 = icmp eq i64 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %15
%20 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%21 = icmp eq i64 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 7)
%24 = icmp eq i64 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = call i32 @print_nice_policy_line(i8* %10)
br label %27
27: ; preds = %25, %15, %19
%28 = call i32 @feof(i32* %1)
%29 = icmp eq i32 %28, 0
br i1 %29, label %15, label %30
30: ; preds = %27, %22, %6
%31 = call i32 @putchar(i32 10)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.11, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @str.12, i64 0, i64 0))
%34 = call i32 @feof(i32* %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %45
36: ; preds = %30, %42
%37 = call i32 @fgets(i8* %10, i32 %7, i32* %1)
%38 = call i64 @strncasecmp(i8* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %36
%41 = call i32 @print_nice_policy_line(i8* %10)
br label %42
42: ; preds = %40, %36
%43 = call i32 @feof(i32* %1)
%44 = icmp eq i32 %43, 0
br i1 %44, label %36, label %45
45: ; preds = %42, %30
%46 = call i32 @fclose(i32* %1)
br label %47
47: ; preds = %45, %3
%48 = phi i32 [ 0, %45 ], [ 1, %3 ]
ret i32 %48
}