#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*/ do_sha256sum(int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int do_sha256sum_file(const char *filename, unsigned char *rptr) {
  FILE *f = fopen(filename, "rb");
  if (f == NULL) {
    fprintf(stderr, "Unable to open file: %s\n", filename);
    return 1;
  }
  do_sha256sum(f, rptr);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<do_sha256sum_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <do_sha256sum_file+0x54>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b1 <do_sha256sum_file+0x71>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <do_sha256sum@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_sha256sum_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xeae(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1176 <do_sha256sum_file+0x36>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <do_sha256sum@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1193 <do_sha256sum_file+0x53>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file: %s\0A\00"
define i32 @do_sha256sum_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %4
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %21
15: ; preds = %2
%16 = load i32*, i32** %6
%17 = load i8*, i8** %5
%18 = call i32 @do_sha256sum(i32* %16, i8* %17)
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
store i32 0, i32* %3
br label %21
21: ; preds = %15, %11
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Unable to open file: %s\0A\00"
define i32 @do_sha256sum_file(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %11
8: ; preds = %2
%9 = tail call i32 @do_sha256sum(i32* %3, i8* %1)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 1, %5 ], [ 0, %8 ]
ret i32 %12
}