#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*/ printf(char *, ...);
int /*<<< orphan*/ task1(char *, char *, char *, char *);
int /*<<< orphan*/ task2(char *, char *, unsigned char *, int *);
int task3(unsigned char *, int, char *);
int /*<<< orphan*/ write_file(char *, unsigned char *, int);
int main() {
  char *cipher_file_name_template = "s73331-cipher0%i.bin";
  char *key_file_name = "s73331-key.bin";
  char *pubkey_file_name = "pubkey.pem";
  char *signature_file_name = "s73331-sig.bin";
  char *hash_output_file_name = "s73331-hash.bin";
  char right_cipher_file_name[16384];
  right_cipher_file_name[0] = 0;
  task1(cipher_file_name_template, pubkey_file_name, signature_file_name,
        right_cipher_file_name);
  if (right_cipher_file_name[0] == 0) {
    printf("No signature matched.\nExiting.");
    return 1;
  }
  printf("\nProgressing with cipher file %s\n", right_cipher_file_name);
  unsigned char buf_plain[16384];
  int bytes_out;
  task2(right_cipher_file_name, key_file_name, buf_plain, &bytes_out);
  if (bytes_out > 0) {
    printf("\nWrote %i bytes to file plain.pdf\n", bytes_out);
    write_file("plain.pdf", buf_plain, bytes_out);
  } else {
    return 2;
  }
  int result = task3(buf_plain, bytes_out, hash_output_file_name);
  printf("\n");
  if (result == 0)
    return 3;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea1(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x30(%rbp)
movb   $0x0,-0x4030(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    -0x4030(%rbp),%rcx
call   1070 <task1@plt>
movsbl -0x4030(%rbp),%eax
cmp    $0x0,%eax
jne    11e2 <main+0x92>
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12aa <main+0x15a>
lea    -0x4030(%rbp),%rsi
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x4030(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x8030(%rbp),%rdx
lea    -0x8034(%rbp),%rcx
call   1030 <task2@plt>
cmpl   $0x0,-0x8034(%rbp)
jle    1254 <main+0x104>
mov    -0x8034(%rbp),%esi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8030(%rbp),%rsi
mov    -0x8034(%rbp),%edx
lea    0xe68(%rip),%rdi
call   1050 <write_file@plt>
jmp    1260 <main+0x110>
movl   $0x2,-0x4(%rbp)
jmp    12aa <main+0x15a>
lea    -0x8030(%rbp),%rdi
mov    -0x8034(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1060 <task3@plt>
mov    %eax,-0x8038(%rbp)
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8038(%rbp)
jne    12a3 <main+0x153>
movl   $0x3,-0x4(%rbp)
jmp    12aa <main+0x15a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x8010,%rsp
movb   $0x0,0x10(%rsp)
lea    0xe8c(%rip),%rdi
lea    0xea9(%rip),%rsi
lea    0xead(%rip),%rdx
lea    0x10(%rsp),%rcx
call   1080 <task1@plt>
cmpb   $0x0,0x10(%rsp)
je     1225 <main+0xc5>
lea    0xecf(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe61(%rip),%rsi
lea    0x4010(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1040 <task2@plt>
mov    0xc(%rsp),%esi
test   %esi,%esi
jle    123a <main+0xda>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xec8(%rip),%rdi
lea    0x4010(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <write_file@plt>
mov    0xc(%rsp),%esi
lea    0xe39(%rip),%rdx
mov    %rbx,%rdi
call   1070 <task3@plt>
mov    %eax,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
test   %ebx,%ebx
sete   %al
lea    (%rax,%rax,2),%eax
jmp    123f <main+0xdf>
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    123f <main+0xdf>
mov    $0x2,%eax
add    $0x8010,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"s73331-cipher0%i.bin\00"
@.str.1 = [15 x i8] c"s73331-key.bin\00"
@.str.2 = [11 x i8] c"pubkey.pem\00"
@.str.3 = [15 x i8] c"s73331-sig.bin\00"
@.str.4 = [16 x i8] c"s73331-hash.bin\00"
@.str.5 = [31 x i8] c"No signature matched.\0AExiting.\00"
@.str.6 = [34 x i8] c"\0AProgressing with cipher file %s\0A\00"
@.str.7 = [35 x i8] c"\0AWrote %i bytes to file plain.pdf\0A\00"
@.str.8 = [10 x i8] c"plain.pdf\00"
@.str.9 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [16384 x i8]
%8 = alloca [16384 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8** %6
%11 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
store i8 0, i8* %11
%12 = load i8*, i8** %2
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%16 = call i32 @task1(i8* %12, i8* %13, i8* %14, i8* %15)
%17 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %49
23: ; preds = %0
%24 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [16384 x i8], [16384 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%29 = call i32 @task2(i8* %26, i8* %27, i8* %28, i32* %9)
%30 = load i32, i32* %9
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %23
%33 = load i32, i32* %9
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%36 = load i32, i32* %9
%37 = call i32 @write_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %35, i32 %36)
br label %39
38: ; preds = %23
store i32 2, i32* %1
br label %49
39: ; preds = %32
%40 = getelementptr inbounds [16384 x i8], [16384 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %9
%42 = load i8*, i8** %6
%43 = call i32 @task3(i8* %40, i32 %41, i8* %42)
store i32 %43, i32* %10
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%45 = load i32, i32* %10
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %39
store i32 3, i32* %1
br label %49
48: ; preds = %39
store i32 0, i32* %1
br label %49
49: ; preds = %48, %47, %38, %21
%50 = load i32, i32* %1
ret i32 %50
}

LLVM IR (-O2):
@.str = [21 x i8] c"s73331-cipher0%i.bin\00"
@.str.1 = [15 x i8] c"s73331-key.bin\00"
@.str.2 = [11 x i8] c"pubkey.pem\00"
@.str.3 = [15 x i8] c"s73331-sig.bin\00"
@.str.4 = [16 x i8] c"s73331-hash.bin\00"
@.str.5 = [31 x i8] c"No signature matched.\0AExiting.\00"
@.str.6 = [34 x i8] c"\0AProgressing with cipher file %s\0A\00"
@.str.7 = [35 x i8] c"\0AWrote %i bytes to file plain.pdf\0A\00"
@.str.8 = [10 x i8] c"plain.pdf\00"
define i32 @main() {
%1 = alloca [16384 x i8]
%2 = alloca [16384 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [16384 x i8], [16384 x i8]* %1, i64 0, i64 0
store i8 0, i8* %4
%5 = call i32 @task1(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %28
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%12 = getelementptr inbounds [16384 x i8], [16384 x i8]* %2, i64 0, i64 0
%13 = bitcast i32* %3 to i8*
%14 = call i32 @task2(i8* %4, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32* %3)
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %10
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.7, i64 0, i64 0), i32 %15)
%19 = load i32, i32* %3
%20 = call i32 @write_file(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %12, i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @task3(i8* %12, i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @putchar(i32 10)
%24 = icmp eq i32 %22, 0
%25 = select i1 %24, i32 3, i32 0
br label %26
26: ; preds = %10, %17
%27 = phi i32 [ %25, %17 ], [ 2, %10 ]
br label %28
28: ; preds = %26, %8
%29 = phi i32 [ 1, %8 ], [ %27, %26 ]
ret i32 %29
}