#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 decode_block0(unsigned char *, int, unsigned char *);
int decode_block1(unsigned char *, int, unsigned char *);
int decode_block2(unsigned char *, int, unsigned char *);
int decode_block3(unsigned char *, int, unsigned char *);
int decode_block4(unsigned char *, int, unsigned char *, unsigned char *);
int decode_block5(unsigned char *, int, unsigned char *, unsigned char *);
int decode_block6(unsigned char *, int, unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int read_file(char *, unsigned char **);
int /*<<< orphan*/ stderr;
int write_file(char *, unsigned char *, int);
int blast_decode_file(char *in_filename, int type, char *out_filename,
                      unsigned char *lut) {
  unsigned char *in_buf = NULL;
  unsigned char *out_buf = NULL;
  int in_len;
  int write_len;
  int out_len = 0;
  int ret_val = 0;
  in_len = read_file(in_filename, &in_buf);
  if (in_len <= 0) {
    return 1;
  }
  out_buf = malloc(100 * in_len);
  if (out_buf == NULL) {
    ret_val = 2;
    goto free_all;
  }
  switch (type) {
  case 0:
    out_len = decode_block0(in_buf, in_len, out_buf);
    break;
  case 1:
    out_len = decode_block1(in_buf, in_len, out_buf);
    break;
  case 2:
    out_len = decode_block2(in_buf, in_len, out_buf);
    break;
  case 4:
    out_len = decode_block4(in_buf, in_len, out_buf, lut);
    break;
  case 5:
    out_len = decode_block5(in_buf, in_len, out_buf, lut);
    break;
  case 3:
    out_len = decode_block3(in_buf, in_len, out_buf);
    break;
  case 6:
    out_len = decode_block6(in_buf, in_len, out_buf);
    break;
  default:
    fprintf(stderr, "Unknown Blast type %d\n", type);
    break;
  }
  write_len = write_file(out_filename, out_buf, out_len);
  if (write_len != out_len) {
    ret_val = 2;
  }
free_all:
  if (out_buf) {
    free(out_buf);
  }
  if (in_buf) {
    free(in_buf);
  }
  return ret_val;
}


x86 assembly (clang, -O0):
<blast_decode_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <read_file@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     121b <blast_decode_file+0x5b>
movl   $0x1,-0x4(%rbp)
jmp    1385 <blast_decode_file+0x1c5>
imul   $0x64,-0x3c(%rbp),%edi
call   10d0 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    123f <blast_decode_file+0x7f>
movl   $0x2,-0x48(%rbp)
jmp    1357 <blast_decode_file+0x197>
mov    -0x14(%rbp),%eax
mov    %rax,-0x50(%rbp)
sub    $0x6,%rax
ja     1314 <blast_decode_file+0x154>
mov    -0x50(%rbp),%rax
lea    0xda5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   10e0 <decode_block0@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   1050 <decode_block1@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   10b0 <decode_block2@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10a0 <decode_block4@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1040 <decode_block5@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   1060 <decode_block3@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    -0x30(%rbp),%rdi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%rdx
call   10c0 <decode_block6@plt>
mov    %eax,-0x44(%rbp)
jmp    132c <blast_decode_file+0x16c>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xcf5(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x44(%rbp),%edx
call   1070 <write_file@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     1352 <blast_decode_file+0x192>
movl   $0x2,-0x48(%rbp)
jmp    1357 <blast_decode_file+0x197>
cmpq   $0x0,-0x38(%rbp)
je     136b <blast_decode_file+0x1ab>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     137f <blast_decode_file+0x1bf>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blast_decode_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %esi,%ebx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
call   1090 <read_file@plt>
test   %eax,%eax
jle    1228 <blast_decode_file+0x68>
mov    %eax,%ebp
imul   $0x64,%eax,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1232 <blast_decode_file+0x72>
mov    %rax,%r12
cmp    $0x6,%ebx
ja     123c <blast_decode_file+0x7c>
mov    %ebx,%eax
lea    0xdf5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   10e0 <decode_block0@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    $0x1,%ebx
jmp    12f0 <blast_decode_file+0x130>
mov    $0x2,%ebx
jmp    12e1 <blast_decode_file+0x121>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdd0(%rip),%rsi
mov    %ebx,%edx
call   1080 <fprintf@plt>
xor    %ebp,%ebp
jmp    12c3 <blast_decode_file+0x103>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1050 <decode_block1@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   10b0 <decode_block2@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   1060 <decode_block3@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   10a0 <decode_block4@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <decode_block5@plt>
jmp    12c1 <blast_decode_file+0x101>
mov    0x8(%rsp),%rdi
mov    %ebp,%esi
mov    %r12,%rdx
call   10c0 <decode_block6@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1070 <write_file@plt>
xor    %ebx,%ebx
cmp    %ebp,%eax
setne  %bl
add    %ebx,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     12f0 <blast_decode_file+0x130>
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Unknown Blast type %d\0A\00"
define i32 @blast_decode_file(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* null, i8** %10
store i8* null, i8** %11
store i32 0, i32* %14
store i32 0, i32* %15
%16 = load i8*, i8** %6
%17 = call i32 @read_file(i8* %16, i8** %10)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp sle i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 1, i32* %5
br label %95
21: ; preds = %4
%22 = load i32, i32* %12
%23 = mul nsw i32 100, %22
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %11
%25 = load i8*, i8** %11
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 2, i32* %15
br label %81
28: ; preds = %21
%29 = load i32, i32* %7
switch i32 %29, label %67 [
i32 0, label %30
i32 1, label %35
i32 2, label %40
i32 4, label %45
i32 5, label %51
i32 3, label %57
i32 6, label %62
]
30: ; preds = %28
%31 = load i8*, i8** %10
%32 = load i32, i32* %12
%33 = load i8*, i8** %11
%34 = call i32 @decode_block0(i8* %31, i32 %32, i8* %33)
store i32 %34, i32* %14
br label %71
35: ; preds = %28
%36 = load i8*, i8** %10
%37 = load i32, i32* %12
%38 = load i8*, i8** %11
%39 = call i32 @decode_block1(i8* %36, i32 %37, i8* %38)
store i32 %39, i32* %14
br label %71
40: ; preds = %28
%41 = load i8*, i8** %10
%42 = load i32, i32* %12
%43 = load i8*, i8** %11
%44 = call i32 @decode_block2(i8* %41, i32 %42, i8* %43)
store i32 %44, i32* %14
br label %71
45: ; preds = %28
%46 = load i8*, i8** %10
%47 = load i32, i32* %12
%48 = load i8*, i8** %11
%49 = load i8*, i8** %9
%50 = call i32 @decode_block4(i8* %46, i32 %47, i8* %48, i8* %49)
store i32 %50, i32* %14
br label %71
51: ; preds = %28
%52 = load i8*, i8** %10
%53 = load i32, i32* %12
%54 = load i8*, i8** %11
%55 = load i8*, i8** %9
%56 = call i32 @decode_block5(i8* %52, i32 %53, i8* %54, i8* %55)
store i32 %56, i32* %14
br label %71
57: ; preds = %28
%58 = load i8*, i8** %10
%59 = load i32, i32* %12
%60 = load i8*, i8** %11
%61 = call i32 @decode_block3(i8* %58, i32 %59, i8* %60)
store i32 %61, i32* %14
br label %71
62: ; preds = %28
%63 = load i8*, i8** %10
%64 = load i32, i32* %12
%65 = load i8*, i8** %11
%66 = call i32 @decode_block6(i8* %63, i32 %64, i8* %65)
store i32 %66, i32* %14
br label %71
67: ; preds = %28
%68 = load i32, i32* @stderr
%69 = load i32, i32* %7
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %67, %62, %57, %51, %45, %40, %35, %30
%72 = load i8*, i8** %8
%73 = load i8*, i8** %11
%74 = load i32, i32* %14
%75 = call i32 @write_file(i8* %72, i8* %73, i32 %74)
store i32 %75, i32* %13
%76 = load i32, i32* %13
%77 = load i32, i32* %14
%78 = icmp ne i32 %76, %77
br i1 %78, label %79, label %80
79: ; preds = %71
store i32 2, i32* %15
br label %80
80: ; preds = %79, %71
br label %81
81: ; preds = %80, %27
%82 = load i8*, i8** %11
%83 = icmp ne i8* %82, null
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i8*, i8** %11
%86 = call i32 @free(i8* %85)
br label %87
87: ; preds = %84, %81
%88 = load i8*, i8** %10
%89 = icmp ne i8* %88, null
br i1 %89, label %90, label %93
90: ; preds = %87
%91 = load i8*, i8** %10
%92 = call i32 @free(i8* %91)
br label %93
93: ; preds = %90, %87
%94 = load i32, i32* %15
store i32 %94, i32* %5
br label %95
95: ; preds = %93, %20
%96 = load i32, i32* %5
ret i32 %96
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Unknown Blast type %d\0A\00"
define i32 @blast_decode_file(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%7 = call i32 @read_file(i8* %0, i8** %5)
%8 = icmp slt i32 %7, 1
br i1 %8, label %50, label %9
9: ; preds = %4
%10 = mul nsw i32 %7, 100
%11 = call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %44, label %13
13: ; preds = %9
switch i32 %1, label %35 [
i32 0, label %14
i32 1, label %17
i32 2, label %20
i32 4, label %23
i32 5, label %26
i32 3, label %29
i32 6, label %32
]
14: ; preds = %13
%15 = load i8*, i8** %5
%16 = call i32 @decode_block0(i8* %15, i32 %7, i8* %11)
br label %38
17: ; preds = %13
%18 = load i8*, i8** %5
%19 = call i32 @decode_block1(i8* %18, i32 %7, i8* %11)
br label %38
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = call i32 @decode_block2(i8* %21, i32 %7, i8* %11)
br label %38
23: ; preds = %13
%24 = load i8*, i8** %5
%25 = call i32 @decode_block4(i8* %24, i32 %7, i8* %11, i8* %3)
br label %38
26: ; preds = %13
%27 = load i8*, i8** %5
%28 = call i32 @decode_block5(i8* %27, i32 %7, i8* %11, i8* %3)
br label %38
29: ; preds = %13
%30 = load i8*, i8** %5
%31 = call i32 @decode_block3(i8* %30, i32 %7, i8* %11)
br label %38
32: ; preds = %13
%33 = load i8*, i8** %5
%34 = call i32 @decode_block6(i8* %33, i32 %7, i8* %11)
br label %38
35: ; preds = %13
%36 = load i32, i32* @stderr
%37 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %38
38: ; preds = %35, %32, %29, %26, %23, %20, %17, %14
%39 = phi i32 [ 0, %35 ], [ %34, %32 ], [ %31, %29 ], [ %28, %26 ], [ %25, %23 ], [ %22, %20 ], [ %19, %17 ], [ %16, %14 ]
%40 = call i32 @write_file(i8* %2, i8* %11, i32 %39)
%41 = icmp eq i32 %40, %39
%42 = select i1 %41, i32 0, i32 2
%43 = call i32 @free(i8* %11)
br label %44
44: ; preds = %9, %38
%45 = phi i32 [ %42, %38 ], [ 2, %9 ]
%46 = load i8*, i8** %5
%47 = icmp eq i8* %46, null
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @free(i8* %46)
br label %50
50: ; preds = %44, %48, %4
%51 = phi i32 [ 1, %4 ], [ %45, %48 ], [ %45, %44 ]
ret i32 %51
}