#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*/ uint64_t;
typedef int uint32_t;

/* Variables and functions */
int cat(char *, int);
int def_region(int, char *, int /*<<< orphan*/, int);
int enter_stacks(int, int /*<<< orphan*/, int);
int exit_stacks(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ print_category(int, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int test_file(uint64_t bid, int message, char *filename) {
  char *category = "file";
  int error = 0, overhead = 0;
  uint32_t rid = 4;
  print_category(message, category);
  error |= def_region(message, category, bid, rid);
  error |= enter_stacks(message, bid, rid);
  if (message == 1)
    printf("\nFile %s:\n", filename);
  printf("bin_file_before=");
  overhead = cat(filename, 0);
  printf("\n");
  if (overhead == -1)
    fprintf(stderr, "Error: %s not readable\n", filename);
  error |= exit_stacks(message, bid, rid);
  if (message == 1)
    printf("\nFile %s:\n", filename);
  printf("bin_file_after=");
  cat(filename, overhead);
  printf("\n");
  if (message == 1)
    printf("*********\n");
  return error;
}


x86 assembly (clang, -O0):
<test_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1080 <print_category@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x4(%rbp),%edx
mov    -0x24(%rbp),%ecx
call   1060 <def_region@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1070 <enter_stacks@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11f6 <test_file+0x86>
mov    -0x10(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1090 <cat@plt>
mov    %eax,-0x20(%rbp)
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1243 <test_file+0xd3>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xde3(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <exit_stacks@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1273 <test_file+0x103>
mov    -0x10(%rbp),%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdbf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1090 <cat@plt>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    12b3 <test_file+0x143>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%r12d
lea    0xe56(%rip),%rbp
mov    %esi,%edi
mov    %rbp,%rsi
call   10a0 <print_category@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
mov    $0x4,%ecx
call   1080 <def_region@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %r12d,%esi
mov    $0x4,%edx
call   1090 <enter_stacks@plt>
mov    %eax,%ebp
cmp    $0x1,%ebx
jne    11f0 <test_file+0x60>
lea    0xe1f(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   10b0 <cat@plt>
mov    %eax,%r13d
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0xffffffff,%r13d
jne    1233 <test_file+0xa3>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
mov    %r15,%rdx
call   1070 <fprintf@plt>
mov    %ebx,%edi
mov    %r12d,%esi
mov    $0x4,%edx
call   1040 <exit_stacks@plt>
mov    %eax,%r12d
cmp    $0x1,%ebx
jne    128c <test_file+0xfc>
lea    0xdb4(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdd7(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
call   10b0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdc4(%rip),%rdi
call   1050 <puts@plt>
jmp    12af <test_file+0x11f>
lea    0xda6(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r13d,%esi
call   10b0 <cat@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
or     %r14d,%ebp
or     %r12d,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"file\00"
@.str.1 = [11 x i8] c"\0AFile %s:\0A\00"
@.str.2 = [17 x i8] c"bin_file_before=\00"
@.str.3 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Error: %s not readable\0A\00"
@.str.5 = [16 x i8] c"bin_file_after=\00"
@.str.6 = [11 x i8] c"*********\0A\00"
define i32 @test_file(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 4, i32* %10
%11 = load i32, i32* %5
%12 = load i8*, i8** %7
%13 = call i32 @print_category(i32 %11, i8* %12)
%14 = load i32, i32* %5
%15 = load i8*, i8** %7
%16 = load i32, i32* %4
%17 = load i32, i32* %10
%18 = call i32 @def_region(i32 %14, i8* %15, i32 %16, i32 %17)
%19 = load i32, i32* %8
%20 = or i32 %19, %18
store i32 %20, i32* %8
%21 = load i32, i32* %5
%22 = load i32, i32* %4
%23 = load i32, i32* %10
%24 = call i32 @enter_stacks(i32 %21, i32 %22, i32 %23)
%25 = load i32, i32* %8
%26 = or i32 %25, %24
store i32 %26, i32* %8
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %3
%30 = load i8*, i8** %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %29, %3
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%34 = load i8*, i8** %6
%35 = call i32 @cat(i8* %34, i32 0)
store i32 %35, i32* %9
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %43
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %6
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39, %32
%44 = load i32, i32* %5
%45 = load i32, i32* %4
%46 = load i32, i32* %10
%47 = call i32 @exit_stacks(i32 %44, i32 %45, i32 %46)
%48 = load i32, i32* %8
%49 = or i32 %48, %47
store i32 %49, i32* %8
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = load i8*, i8** %6
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %43
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%57 = load i8*, i8** %6
%58 = load i32, i32* %9
%59 = call i32 @cat(i8* %57, i32 %58)
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* %5
%62 = icmp eq i32 %61, 1
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %65
65: ; preds = %63, %55
%66 = load i32, i32* %8
ret i32 %66
}

LLVM IR (-O2):
@.str = [5 x i8] c"file\00"
@.str.1 = [11 x i8] c"\0AFile %s:\0A\00"
@.str.2 = [17 x i8] c"bin_file_before=\00"
@stderr = global i32 0
@.str.4 = [24 x i8] c"Error: %s not readable\0A\00"
@.str.5 = [16 x i8] c"bin_file_after=\00"
@str = [10 x i8] c"*********\00"
define i32 @test_file(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32 @print_category(i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @def_region(i32 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %0, i32 4)
%6 = tail call i32 @enter_stacks(i32 %1, i32 %0, i32 4)
%7 = icmp eq i32 %1, 1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %10
10: ; preds = %8, %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @cat(i8* %2, i32 0)
%13 = tail call i32 @putchar(i32 10)
%14 = icmp eq i32 %12, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %18
18: ; preds = %15, %10
%19 = tail call i32 @exit_stacks(i32 %1, i32 %0, i32 4)
br i1 %7, label %20, label %26
20: ; preds = %18
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 @cat(i8* %2, i32 %12)
%24 = tail call i32 @putchar(i32 10)
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
br label %30
26: ; preds = %18
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%28 = tail call i32 @cat(i8* %2, i32 %12)
%29 = tail call i32 @putchar(i32 10)
br label %30
30: ; preds = %26, %20
%31 = or i32 %6, %5
%32 = or i32 %31, %19
ret i32 %32
}