#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ histo_one_fp(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
void histo_one_file(char *filename) {
  FILE *fp;
  unsigned file_size;
  unsigned char line[512];
  unsigned counts[256];
  int num_read;
  int i;
  int j;
  int n;
  unsigned min;
  unsigned max;
  fp = fopen(filename, "rb");
  if (fp == 0) {
    fprintf(stderr, "Couldn't open input file \"%s\" for binary read.\n",
            filename);
    return;
  }
  histo_one_fp(fp, filename);
  fclose(fp);
}


x86 assembly (clang, -O0):
<histo_one_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118c <histo_one_file+0x4c>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11a2 <histo_one_file+0x62>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <histo_one_fp@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<histo_one_file>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1175 <histo_one_file+0x35>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1050 <histo_one_fp@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <fclose@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Couldn't open input file \22%s\22 for binary read.\0A\00"
define void @histo_one_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca [256 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %2
%13 = load i8*, i8** %2
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %3
%15 = load i32*, i32** %3
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %1
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %2
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %27
21: ; preds = %1
%22 = load i32*, i32** %3
%23 = load i8*, i8** %2
%24 = call i32 @histo_one_fp(i32* %22, i8* %23)
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
br label %27
27: ; preds = %21, %17
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [48 x i8] c"Couldn't open input file \22%s\22 for binary read.\0A\00"
define void @histo_one_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %10
7: ; preds = %1
%8 = tail call i32 @histo_one_fp(i32* %2, i8* %0)
%9 = tail call i32 @fclose(i32* %2)
br label %10
10: ; preds = %7, %4
ret void
}