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

/* Variables and functions */
int /*<<< orphan*/ diag_destroy(long *, long *);
int /*<<< orphan*/ diag_init(long, long, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
unsigned int fread_unescape(int /*<<< orphan*/ *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ handle_diag(int /*<<< orphan*/ *, unsigned int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
void process_file(long *sid, long *cid, char *gsmtap_target, char *infile_name,
                  uint32_t appid) {
  uint8_t msg[4096];
  FILE *infile = NULL;
  unsigned len = 0;
  if (strcmp(infile_name, "-") == 0) {
    infile = stdin;
  } else {
    infile = fopen(infile_name, "rb");
  }
  if (!infile) {
    err(1, "Cannot open input file: %s", infile_name);
  }
  diag_init(*sid, *cid, gsmtap_target, infile_name, appid);
  for (;;) {
    memset(msg, 0x2b, sizeof(msg));
    len = fread_unescape(infile, msg, sizeof(msg));
    if (!len) {
      break;
    }
    handle_diag(msg, len);
  }
  diag_destroy(sid, cid);
  fclose(infile);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movq   $0x0,-0x4038(%rbp)
movl   $0x0,-0x403c(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11f4 <process_file+0x64>
mov    0x2e03(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x4038(%rbp)
jmp    120b <process_file+0x7b>
mov    -0x20(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x4038(%rbp)
cmpq   $0x0,-0x4038(%rbp)
jne    122e <process_file+0x9e>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xddc(%rip),%rsi
call   1090 <err@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
call   1050 <diag_init@plt>
lea    -0x4030(%rbp),%rdi
mov    $0x2b,%esi
mov    $0x4000,%edx
call   1070 <memset@plt>
mov    -0x4038(%rbp),%rdi
lea    -0x4030(%rbp),%rsi
mov    $0x4000,%edx
call   10a0 <fread_unescape@plt>
mov    %eax,-0x403c(%rbp)
cmpl   $0x0,-0x403c(%rbp)
jne    1293 <process_file+0x103>
jmp    12aa <process_file+0x11a>
lea    -0x4030(%rbp),%rdi
mov    -0x403c(%rbp),%esi
call   1060 <handle_diag@plt>
jmp    124d <process_file+0xbd>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <diag_destroy@plt>
mov    -0x4038(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x4040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4008,%rsp
mov    %r8d,%r12d
mov    %rcx,%rbp
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe49(%rip),%rsi
mov    %rcx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1295 <process_file+0x105>
lea    0xe33(%rip),%rsi
mov    %rbp,%rdi
call   10b0 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    11f3 <process_file+0x63>
lea    0xe1f(%rip),%rsi
mov    $0x1,%edi
mov    %rbp,%rdx
call   1090 <err@plt>
mov    (%r15),%rdi
mov    (%r14),%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r12d,%r8d
call   1050 <diag_init@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x2b,%esi
mov    $0x4000,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x4000,%edx
call   10a0 <fread_unescape@plt>
test   %eax,%eax
je     1270 <process_file+0xe0>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    %eax,%esi
call   1060 <handle_diag@plt>
mov    %rbp,%rdi
mov    $0x2b,%esi
mov    $0x4000,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x4000,%edx
call   10a0 <fread_unescape@plt>
test   %eax,%eax
jne    1240 <process_file+0xb0>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <diag_destroy@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x4008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4c(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    11f3 <process_file+0x63>
jmp    11df <process_file+0x4f>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"Cannot open input file: %s\00"
define void @process_file(i64* %0, i64* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca [4096 x i32]
%12 = alloca i32*
%13 = alloca i32
store i64* %0, i64** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32* null, i32** %12
store i32 0, i32* %13
%14 = load i8*, i8** %9
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %5
%18 = load i32*, i32** @stdin
store i32* %18, i32** %12
br label %22
19: ; preds = %5
%20 = load i8*, i8** %9
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %12
br label %22
22: ; preds = %19, %17
%23 = load i32*, i32** %12
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i8*, i8** %9
%27 = call i32 @err(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %25, %22
%29 = load i64*, i64** %6
%30 = load i64, i64* %29
%31 = load i64*, i64** %7
%32 = load i64, i64* %31
%33 = load i8*, i8** %8
%34 = load i8*, i8** %9
%35 = load i32, i32* %10
%36 = call i32 @diag_init(i64 %30, i64 %32, i8* %33, i8* %34, i32 %35)
br label %37
37: ; preds = %46, %28
%38 = getelementptr inbounds [4096 x i32], [4096 x i32]* %11, i64 0, i64 0
%39 = call i32 @memset(i32* %38, i32 43, i32 16384)
%40 = load i32*, i32** %12
%41 = getelementptr inbounds [4096 x i32], [4096 x i32]* %11, i64 0, i64 0
%42 = call i32 @fread_unescape(i32* %40, i32* %41, i32 16384)
store i32 %42, i32* %13
%43 = load i32, i32* %13
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %37
br label %50
46: ; preds = %37
%47 = getelementptr inbounds [4096 x i32], [4096 x i32]* %11, i64 0, i64 0
%48 = load i32, i32* %13
%49 = call i32 @handle_diag(i32* %47, i32 %48)
br label %37
50: ; preds = %45
%51 = load i64*, i64** %6
%52 = load i64*, i64** %7
%53 = call i32 @diag_destroy(i64* %51, i64* %52)
%54 = load i32*, i32** %12
%55 = call i32 @fclose(i32* %54)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"Cannot open input file: %s\00"
define void @process_file(i64* %0, i64* %1, i8* %2, i8* %3, i32 %4) {
%6 = alloca [4096 x i32]
%7 = bitcast [4096 x i32]* %6 to i8*
%8 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %5
%11 = load i32*, i32** @stdin
br label %14
12: ; preds = %5
%13 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %10
%15 = phi i32* [ %11, %10 ], [ %13, %12 ]
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %19
19: ; preds = %17, %14
%20 = load i64, i64* %0
%21 = load i64, i64* %1
%22 = tail call i32 @diag_init(i64 %20, i64 %21, i8* %2, i8* %3, i32 %4)
%23 = getelementptr inbounds [4096 x i32], [4096 x i32]* %6, i64 0, i64 0
%24 = call i32 @memset(i32* %23, i32 43, i32 16384)
%25 = call i32 @fread_unescape(i32* %15, i32* %23, i32 16384)
%26 = icmp eq i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %19, %27
%28 = phi i32 [ %31, %27 ], [ %25, %19 ]
%29 = call i32 @handle_diag(i32* %23, i32 %28)
%30 = call i32 @memset(i32* %23, i32 43, i32 16384)
%31 = call i32 @fread_unescape(i32* %15, i32* %23, i32 16384)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %27
33: ; preds = %27, %19
%34 = call i32 @diag_destroy(i64* %0, i64* %1)
%35 = call i32 @fclose(i32* %15)
ret void
}