#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*/ uint32_t;

/* Variables and functions */
int EIO;
#define JFFS2_COMPR_DYNRUBIN 133
#define JFFS2_COMPR_NONE 132
#define JFFS2_COMPR_RTIME 131
#define JFFS2_COMPR_RUBINMIPS 130
#define JFFS2_COMPR_ZERO 129
#define JFFS2_COMPR_ZLIB 128
int /*<<< orphan*/ jffs2_dynrubin_decompress(unsigned char *, unsigned char *,
                                             int /*<<< orphan*/,
                                             int /*<<< orphan*/);
int /*<<< orphan*/ jffs2_rtime_decompress(unsigned char *, unsigned char *,
                                          int /*<<< orphan*/,
                                          int /*<<< orphan*/);
int /*<<< orphan*/ jffs2_zlib_decompress(unsigned char *, unsigned char *,
                                         int /*<<< orphan*/,
                                         int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in,
                     unsigned char *data_out, uint32_t cdatalen,
                     uint32_t datalen) {
  switch (comprtype) {
  case JFFS2_COMPR_NONE:
    memcpy(data_out, cdata_in, datalen);
    break;
  case JFFS2_COMPR_ZERO:
    memset(data_out, 0, datalen);
    break;
  case JFFS2_COMPR_ZLIB:
    jffs2_zlib_decompress(cdata_in, data_out, cdatalen, datalen);
    break;
  case JFFS2_COMPR_RTIME:
    jffs2_rtime_decompress(cdata_in, data_out, cdatalen, datalen);
    break;
  case JFFS2_COMPR_RUBINMIPS:
    printf("JFFS2: Rubinmips compression encountered but support not compiled "
           "in!\n");
    break;
  case JFFS2_COMPR_DYNRUBIN:
    jffs2_dynrubin_decompress(cdata_in, data_out, cdatalen, datalen);
    break;
  default:
    printf("Unknown JFFS2 compression type 0x%02x\n", comprtype);
    return -EIO;
  }
  return 0;
}


x86 assembly (clang, -O0):
<jffs2_decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movzbl -0x5(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     122a <jffs2_decompress+0xca>
mov    -0x28(%rbp),%rax
lea    0xe62(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1060 <memcpy@plt>
jmp    124f <jffs2_decompress+0xef>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    124f <jffs2_decompress+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1080 <jffs2_zlib_decompress@plt>
jmp    124f <jffs2_decompress+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1070 <jffs2_rtime_decompress@plt>
jmp    124f <jffs2_decompress+0xef>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124f <jffs2_decompress+0xef>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1030 <jffs2_dynrubin_decompress@plt>
jmp    124f <jffs2_decompress+0xef>
movzbl -0x5(%rbp),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
mov    0x2d9b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1256 <jffs2_decompress+0xf6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jffs2_decompress>:
push   %rbx
lea    -0x80(%rdi),%eax
cmp    $0x5,%al
ja     119d <jffs2_decompress+0x2d>
movzbl %al,%eax
lea    0xe7e(%rip),%rdi
movslq (%rdi,%rax,4),%rax
add    %rdi,%rax
jmp    *%rax
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1090 <jffs2_zlib_decompress@plt>
jmp    120a <jffs2_decompress+0x9a>
movzbl %dil,%esi
lea    0xe70(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e28(%rip),%rax
sub    (%rax),%ebx
jmp    120c <jffs2_decompress+0x9c>
xor    %ebx,%ebx
mov    %rdx,%rdi
xor    %esi,%esi
mov    %r8d,%edx
call   1060 <memset@plt>
jmp    120c <jffs2_decompress+0x9c>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
jmp    120a <jffs2_decompress+0x9a>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1080 <jffs2_rtime_decompress@plt>
jmp    120a <jffs2_decompress+0x9a>
mov    %rdx,%rdi
mov    %r8d,%edx
call   1070 <memcpy@plt>
jmp    120a <jffs2_decompress+0x9a>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
call   1030 <jffs2_dynrubin_decompress@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [71 x i8] c"JFFS2: Rubinmips compression encountered but support not compiled in!\0A\00"
@.str.1 = [39 x i8] c"Unknown JFFS2 compression type 0x%02x\0A\00"
@EIO = global i32 0
define i32 @jffs2_decompress(i8 zeroext %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8 %0, i8* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%12 = load i8, i8* %7
%13 = zext i8 %12 to i32
switch i32 %13, label %43 [
i32 132, label %14
i32 129, label %19
i32 128, label %23
i32 131, label %29
i32 130, label %35
i32 133, label %37
]
14: ; preds = %5
%15 = load i8*, i8** %9
%16 = load i8*, i8** %8
%17 = load i32, i32* %11
%18 = call i32 @memcpy(i8* %15, i8* %16, i32 %17)
br label %49
19: ; preds = %5
%20 = load i8*, i8** %9
%21 = load i32, i32* %11
%22 = call i32 @memset(i8* %20, i32 0, i32 %21)
br label %49
23: ; preds = %5
%24 = load i8*, i8** %8
%25 = load i8*, i8** %9
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = call i32 @jffs2_zlib_decompress(i8* %24, i8* %25, i32 %26, i32 %27)
br label %49
29: ; preds = %5
%30 = load i8*, i8** %8
%31 = load i8*, i8** %9
%32 = load i32, i32* %10
%33 = load i32, i32* %11
%34 = call i32 @jffs2_rtime_decompress(i8* %30, i8* %31, i32 %32, i32 %33)
br label %49
35: ; preds = %5
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str, i64 0, i64 0))
br label %49
37: ; preds = %5
%38 = load i8*, i8** %8
%39 = load i8*, i8** %9
%40 = load i32, i32* %10
%41 = load i32, i32* %11
%42 = call i32 @jffs2_dynrubin_decompress(i8* %38, i8* %39, i32 %40, i32 %41)
br label %49
43: ; preds = %5
%44 = load i8, i8* %7
%45 = zext i8 %44 to i32
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = load i32, i32* @EIO
%48 = sub nsw i32 0, %47
store i32 %48, i32* %6
br label %50
49: ; preds = %37, %35, %29, %23, %19, %14
store i32 0, i32* %6
br label %50
50: ; preds = %49, %43
%51 = load i32, i32* %6
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [39 x i8] c"Unknown JFFS2 compression type 0x%02x\0A\00"
@EIO = global i32 0
@str = [70 x i8] c"JFFS2: Rubinmips compression encountered but support not compiled in!\00"
define i32 @jffs2_decompress(i8 zeroext %0, i8* %1, i8* %2, i32 %3, i32 %4) {
switch i8 %0, label %18 [
i8 -124, label %6
i8 -127, label %8
i8 -128, label %10
i8 -125, label %12
i8 -126, label %14
i8 -123, label %16
]
6: ; preds = %5
%7 = tail call i32 @memcpy(i8* %2, i8* %1, i32 %4)
br label %23
8: ; preds = %5
%9 = tail call i32 @memset(i8* %2, i32 0, i32 %4)
br label %23
10: ; preds = %5
%11 = tail call i32 @jffs2_zlib_decompress(i8* %1, i8* %2, i32 %3, i32 %4)
br label %23
12: ; preds = %5
%13 = tail call i32 @jffs2_rtime_decompress(i8* %1, i8* %2, i32 %3, i32 %4)
br label %23
14: ; preds = %5
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @str, i64 0, i64 0))
br label %23
16: ; preds = %5
%17 = tail call i32 @jffs2_dynrubin_decompress(i8* %1, i8* %2, i32 %3, i32 %4)
br label %23
18: ; preds = %5
%19 = zext i8 %0 to i32
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EIO
%22 = sub nsw i32 0, %21
br label %23
23: ; preds = %6, %8, %10, %12, %14, %16, %18
%24 = phi i32 [ %22, %18 ], [ 0, %16 ], [ 0, %14 ], [ 0, %12 ], [ 0, %10 ], [ 0, %8 ], [ 0, %6 ]
ret i32 %24
}