#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
char *base64_to_sha256_binary(char *);
char *data_to_sha256_base64_encoded(char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Specify inputfile\n");
    return -1;
  }
  FILE *infp = fopen(argv[1], "rb");
  fseek(infp, 0, SEEK_END);
  int test_size = ftell(infp);
  fseek(infp, 0, SEEK_SET);
  char test[test_size];
  fread(test, test_size, 1, infp);
  fclose(infp);
  char *outb2 = data_to_sha256_base64_encoded(test, test_size);
  printf("HASH: %s\n", outb2);
  char *output = base64_to_sha256_binary(outb2);
  FILE *outfp = fopen("output.bin", "wb");
  fwrite(output, 32, 1, outfp);
  fclose(outfp);
  free(output);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11da <main+0x3a>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <main+0x140>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe2a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2deb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
mov    %esi,-0x54(%rbp)
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1090 <ftell@plt>
mov    -0x54(%rbp),%esi
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2db5(%rip),%rax
mov    (%rax),%edx
call   10a0 <fseek@plt>
mov    -0x1c(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x50(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <data_to_sha256_base64_encoded@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <base64_to_sha256_binary@plt>
mov    %rax,-0x40(%rbp)
lea    0xd80(%rip),%rdi
lea    0xd84(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rcx
mov    $0x20,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    -0x48(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11da <main+0x2a>
lea    0xe51(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%r14d
jmp    12bb <main+0x10b>
mov    0x8(%rsi),%rdi
lea    0xe1b(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r12
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
call   10a0 <ftell@plt>
mov    %eax,%r15d
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %rsp,%r13
mov    %r15d,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   1060 <fread@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1040 <data_to_sha256_base64_encoded@plt>
mov    %rax,%rbx
lea    0xd9b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1080 <base64_to_sha256_binary@plt>
mov    %rax,%r15
lea    0xd89(%rip),%rdi
lea    0xd8d(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Specify inputfile\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [10 x i8] c"HASH: %s\0A\00"
@.str.3 = [11 x i8] c"output.bin\00"
@.str.4 = [3 x i8] c"wb\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %6
%26 = call i32 @ftell(i32* %25)
store i32 %26, i32* %7
%27 = load i32*, i32** %6
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i32, i32* %7
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %8
%33 = alloca i8, i64 %31
store i64 %31, i64* %9
%34 = load i32, i32* %7
%35 = load i32*, i32** %6
%36 = call i32 @fread(i8* %33, i32 %34, i32 1, i32* %35)
%37 = load i32*, i32** %6
%38 = call i32 @fclose(i32* %37)
%39 = load i32, i32* %7
%40 = call i8* @data_to_sha256_base64_encoded(i8* %33, i32 %39)
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %10
%44 = call i8* @base64_to_sha256_binary(i8* %43)
store i8* %44, i8** %11
%45 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %45, i32** %12
%46 = load i8*, i8** %11
%47 = load i32*, i32** %12
%48 = call i32 @fwrite(i8* %46, i32 32, i32 1, i32* %47)
%49 = load i32*, i32** %12
%50 = call i32 @fclose(i32* %49)
%51 = load i8*, i8** %11
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %8
br label %54
54: ; preds = %17, %15
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [10 x i8] c"HASH: %s\0A\00"
@.str.3 = [11 x i8] c"output.bin\00"
@.str.4 = [3 x i8] c"wb\00"
@str = [18 x i8] c"Specify inputfile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %27
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @SEEK_END
%11 = tail call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = tail call i32 @ftell(i32* %9)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i32* %9, i32 0, i32 %13)
%15 = zext i32 %12 to i64
%16 = tail call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = call i32 @fread(i8* %17, i32 %12, i32 1, i32* %9)
%19 = tail call i32 @fclose(i32* %9)
%20 = call i8* @data_to_sha256_base64_encoded(i8* %17, i32 %12)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i8* @base64_to_sha256_binary(i8* %20)
%23 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @fwrite(i8* %22, i32 32, i32 1, i32* %23)
%25 = call i32 @fclose(i32* %23)
%26 = call i32 @free(i8* %22)
br label %27
27: ; preds = %6, %4
%28 = phi i32 [ -1, %4 ], [ 0, %6 ]
ret i32 %28
}