#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 kirk_CMD1(void *, void *, int);
int /*<<< orphan*/ printf(char *);
int DecryptIplBlock(void *dst, const void *src) {
  int ret = kirk_CMD1(dst, (void *)src, 0x1000);
  if (ret == 1) {
    printf("KIRK not enabled!\n");
    return -1;
  } else if (ret == 2) {
    printf("Mode in header not CMD1\n");
    return -1;
  } else if (ret == 3) {
    printf("header hash check failed\n");
    return -1;
  } else if (ret == 4) {
    printf("data hash check failed\n");
    return -1;
  } else if (ret == 0x10) {
    printf("data size = 0\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<DecryptIplBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <kirk_CMD1@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1167 <DecryptIplBlock+0x47>
lea    0xeaa(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <DecryptIplBlock+0xea>
cmpl   $0x2,-0x1c(%rbp)
jne    1189 <DecryptIplBlock+0x69>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <DecryptIplBlock+0xea>
cmpl   $0x3,-0x1c(%rbp)
jne    11ab <DecryptIplBlock+0x8b>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <DecryptIplBlock+0xea>
cmpl   $0x4,-0x1c(%rbp)
jne    11cd <DecryptIplBlock+0xad>
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <DecryptIplBlock+0xea>
cmpl   $0x10,-0x1c(%rbp)
jne    11ef <DecryptIplBlock+0xcf>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    120a <DecryptIplBlock+0xea>
jmp    11f4 <DecryptIplBlock+0xd4>
jmp    11f9 <DecryptIplBlock+0xd9>
jmp    11fe <DecryptIplBlock+0xde>
jmp    1203 <DecryptIplBlock+0xe3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DecryptIplBlock>:
push   %rax
mov    $0x1000,%edx
call   1040 <kirk_CMD1@plt>
mov    %eax,%ecx
xor    %eax,%eax
add    $0xffffffff,%ecx
cmp    $0xf,%ecx
ja     117a <DecryptIplBlock+0x5a>
lea    0xf58(%rip),%rdi
lea    0xebb(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
lea    0xf29(%rip),%rdi
jmp    1170 <DecryptIplBlock+0x50>
lea    0xf07(%rip),%rdi
jmp    1170 <DecryptIplBlock+0x50>
lea    0xee7(%rip),%rdi
jmp    1170 <DecryptIplBlock+0x50>
lea    0xed0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"KIRK not enabled!\0A\00"
@.str.1 = [25 x i8] c"Mode in header not CMD1\0A\00"
@.str.2 = [26 x i8] c"header hash check failed\0A\00"
@.str.3 = [24 x i8] c"data hash check failed\0A\00"
@.str.4 = [15 x i8] c"data size = 0\0A\00"
define i32 @DecryptIplBlock(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %5
%9 = call i32 @kirk_CMD1(i8* %7, i8* %8, i32 4096)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
19: ; preds = %14
%20 = load i32, i32* %6
%21 = icmp eq i32 %20, 3
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 4
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
29: ; preds = %24
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 16
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %39
34: ; preds = %29
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
store i32 0, i32* %3
br label %39
39: ; preds = %38, %32, %27, %22, %17, %12
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@str = [14 x i8] c"data size = 0\00"
@str.5 = [23 x i8] c"data hash check failed\00"
@str.6 = [25 x i8] c"header hash check failed\00"
@str.7 = [24 x i8] c"Mode in header not CMD1\00"
@str.8 = [18 x i8] c"KIRK not enabled!\00"
define i32 @DecryptIplBlock(i8* %0, i8* %1) {
%3 = tail call i32 @kirk_CMD1(i8* %0, i8* %1, i32 4096)
switch i32 %3, label %11 [
i32 1, label %8
i32 2, label %4
i32 3, label %5
i32 4, label %6
i32 16, label %7
]
4: ; preds = %2
br label %8
5: ; preds = %2
br label %8
6: ; preds = %2
br label %8
7: ; preds = %2
br label %8
8: ; preds = %2, %4, %5, %6, %7
%9 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0), %6 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @str.6, i64 0, i64 0), %5 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0), %4 ], [ getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0), %2 ]
%10 = tail call i32 @puts(i8* dereferenceable(1) %9)
br label %11
11: ; preds = %8, %2
%12 = phi i32 [ 0, %2 ], [ -1, %8 ]
ret i32 %12
}