#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int maxFreqFromBinFile(int /*<<< orphan*/ *, int *, int);
int /*<<< orphan*/ printf(char *, char *);
int getMaxFreqPerDoc(char *filePath, int *maxFreq, int docs) {
  FILE *maxFreqFile = fopen(filePath, "r");
  if (maxFreqFile == NULL) {
    printf("Error! No max. freq. per doc file in path %s\n", filePath);
    return -1;
  }
  int status = maxFreqFromBinFile(maxFreqFile, maxFreq, docs);
  fclose(maxFreqFile);
  return (status == 1) ? 1 : -1;
}


x86 assembly (clang, -O0):
<getMaxFreqPerDoc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    118e <getMaxFreqPerDoc+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c0 <getMaxFreqPerDoc+0x80>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <maxFreqFromBinFile@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x2c(%rbp),%edx
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMaxFreqPerDoc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118b <getMaxFreqPerDoc+0x4b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <maxFreqFromBinFile@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
cmp    $0x1,%ebp
sete   %al
add    %eax,%eax
add    $0xffffffff,%eax
jmp    119f <getMaxFreqPerDoc+0x5f>
lea    0xe70(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [46 x i8] c"Error! No max. freq. per doc file in path %s\0A\00"
define i32 @getMaxFreqPerDoc(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %15)
store i32 -1, i32* %4
br label %28
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i32*, i32** %6
%20 = load i32, i32* %7
%21 = call i32 @maxFreqFromBinFile(i32* %18, i32* %19, i32 %20)
store i32 %21, i32* %9
%22 = load i32*, i32** %8
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, 1
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 1, i32 -1
store i32 %27, i32* %4
br label %28
28: ; preds = %17, %14
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [46 x i8] c"Error! No max. freq. per doc file in path %s\0A\00"
define i32 @getMaxFreqPerDoc(i8* %0, i32* %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %13
8: ; preds = %3
%9 = tail call i32 @maxFreqFromBinFile(i32* %4, i32* %1, i32 %2)
%10 = tail call i32 @fclose(i32* %4)
%11 = icmp eq i32 %9, 1
%12 = select i1 %11, i32 1, i32 -1
br label %13
13: ; preds = %8, %6
%14 = phi i32 [ -1, %6 ], [ %12, %8 ]
ret i32 %14
}