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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int sha2_file(char *, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int sha2_wrapper(char *filename, unsigned char *sum) {
  int ret = sha2_file(filename, sum, 0);
  if (ret == 1)
    fprintf(stderr, "failed to open: %s\n", filename);
  if (ret == 2)
    fprintf(stderr, "failed to read: %s\n", filename);
  return (ret);
}


x86 assembly (clang, -O0):
<sha2_wrapper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <sha2_file@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    1165 <sha2_wrapper+0x45>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xea0(%rip),%rsi
call   1030 <fprintf@plt>
cmpl   $0x2,-0x14(%rbp)
jne    1188 <sha2_wrapper+0x68>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe91(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha2_wrapper>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edx,%edx
call   1040 <sha2_file@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
je     1142 <sha2_wrapper+0x22>
cmp    $0x2,%ebp
jne    115a <sha2_wrapper+0x3a>
lea    0xed4(%rip),%rsi
jmp    1149 <sha2_wrapper+0x29>
lea    0xeb7(%rip),%rsi
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"failed to open: %s\0A\00"
@.str.1 = [20 x i8] c"failed to read: %s\0A\00"
define i32 @sha2_wrapper(i8* %0, i8* %1) {
%3 = tail call i32 @sha2_file(i8* %0, i8* %1, i32 0)
switch i32 %3, label %9 [
i32 1, label %5
i32 2, label %4
]
4: ; preds = %2
br label %5
5: ; preds = %2, %4
%6 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), %2 ]
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* %6, i8* %0)
br label %9
9: ; preds = %5, %2
ret i32 %3
}