#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;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ sha256_32_vector(int, int /*<<< orphan*/ **, size_t *);
scalar_t__ sha256_file(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int sha256_32_file(const char *file, uint32_t *nid) {
  uint8_t hash[32];
  uint8_t *hash_ptr = hash;
  if (sha256_file(file, hash) < 0) {
    fprintf(stderr, "error: could not calculate SHA256 of '%s'\n", file);
    return -1;
  }
  size_t len = 32;
  *nid = sha256_32_vector(1, &hash_ptr, &len);
  return 0;
}


x86 assembly (clang, -O0):
<sha256_32_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1040 <sha256_file@plt>
cmp    $0x0,%rax
jge    1190 <sha256_32_file+0x60>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe81(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <sha256_32_file+0x92>
movq   $0x20,-0xb0(%rbp)
mov    $0x1,%edi
lea    -0xa8(%rbp),%rsi
lea    -0xb0(%rbp),%rdx
call   1050 <sha256_32_vector@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha256_32_file>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
mov    %rsi,0x8(%rsp)
call   1040 <sha256_file@plt>
test   %rax,%rax
js     1175 <sha256_32_file+0x45>
movq   $0x20,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
mov    $0x1,%edi
call   1050 <sha256_32_vector@plt>
mov    %eax,(%r14)
xor    %eax,%eax
jmp    1192 <sha256_32_file+0x62>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    %rbx,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"error: could not calculate SHA256 of '%s'\0A\00"
define i32 @sha256_32_file(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [32 x i32]
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
store i32* %9, i32** %7
%10 = load i8*, i8** %4
%11 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%12 = call i64 @sha256_file(i8* %10, i32* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %3
br label %21
18: ; preds = %2
store i64 32, i64* %8
%19 = call i32 @sha256_32_vector(i32 1, i32** %7, i64* %8)
%20 = load i32*, i32** %5
store i32 %19, i32* %20
store i32 0, i32* %3
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"error: could not calculate SHA256 of '%s'\0A\00"
define i32 @sha256_32_file(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [32 x i32]
%4 = alloca i32*
%5 = alloca i64
%6 = bitcast [32 x i32]* %3 to i8*
%7 = bitcast i32** %4 to i8*
%8 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
store i32* %8, i32** %4
%9 = call i64 @sha256_file(i8* %0, i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
14: ; preds = %2
%15 = bitcast i64* %5 to i8*
store i64 32, i64* %5
%16 = call i32 @sha256_32_vector(i32 1, i32** %4, i64* %5)
store i32 %16, i32* %1
br label %17
17: ; preds = %14, %11
%18 = phi i32 [ -1, %11 ], [ 0, %14 ]
ret i32 %18
}