#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);
int kirk_CMD10(void *, int);
int kirk_CMD11(void *, void *, int);
int kirk_CMD4(void *, void *, int);
int kirk_CMD7(void *, void *, int);
int sceUtilsBufferCopyWithRange(void *outbuff, int outsize, void *inbuff,
                                int insize, int cmd) {
  switch (cmd) {
  case 1:
    if (insize % 16)
      return 0x90A;
    int ret = kirk_CMD1(outbuff, inbuff, insize, 1);
    if (ret == 3)
      return 0x920;
    return ret;
    break;
  case 4:
    return kirk_CMD4(outbuff, inbuff, insize);
    break;
  case 7:
    return kirk_CMD7(outbuff, inbuff, insize);
    break;
  case 10:
    return kirk_CMD10(inbuff, insize);
    break;
  case 11:
    return kirk_CMD11(outbuff, inbuff, insize);
    break;
  }
  return -1;
}


x86 assembly (clang, -O0):
<sceUtilsBufferCopyWithRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0xa,%eax
ja     1248 <sceUtilsBufferCopyWithRange+0xf8>
mov    -0x38(%rbp),%rax
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11b3 <sceUtilsBufferCopyWithRange+0x63>
movl   $0x90a,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x1,%ecx
call   1040 <kirk_CMD1@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x3,-0x2c(%rbp)
jne    11e1 <sceUtilsBufferCopyWithRange+0x91>
movl   $0x920,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1060 <kirk_CMD4@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <kirk_CMD7@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1050 <kirk_CMD10@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <kirk_CMD11@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <sceUtilsBufferCopyWithRange+0xff>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sceUtilsBufferCopyWithRange>:
push   %rax
mov    $0xffffffff,%eax
add    $0xffffffff,%r8d
cmp    $0xa,%r8d
ja     117a <sceUtilsBufferCopyWithRange+0x2a>
lea    0xe99(%rip),%r9
movslq (%r9,%r8,4),%rsi
add    %r9,%rsi
jmp    *%rsi
mov    $0x90a,%eax
test   $0xf,%cl
je     11a8 <sceUtilsBufferCopyWithRange+0x58>
pop    %rcx
ret
mov    %rdx,%rsi
mov    %ecx,%edx
pop    %rax
jmp    1060 <kirk_CMD4@plt>
mov    %rdx,%rsi
mov    %ecx,%edx
pop    %rax
jmp    1030 <kirk_CMD7@plt>
mov    %rdx,%rdi
mov    %ecx,%esi
pop    %rax
jmp    1050 <kirk_CMD10@plt>
mov    %rdx,%rsi
mov    %ecx,%edx
pop    %rax
jmp    1070 <kirk_CMD11@plt>
mov    %rdx,%rsi
mov    %ecx,%edx
mov    $0x1,%ecx
call   1040 <kirk_CMD1@plt>
mov    %eax,%ecx
cmp    $0x3,%eax
mov    $0x920,%eax
cmovne %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @sceUtilsBufferCopyWithRange(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i32, i32* %11
switch i32 %13, label %48 [
i32 1, label %14
i32 4, label %29
i32 7, label %34
i32 10, label %39
i32 11, label %43
]
14: ; preds = %5
%15 = load i32, i32* %10
%16 = srem i32 %15, 16
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 2314, i32* %6
br label %49
19: ; preds = %14
%20 = load i8*, i8** %7
%21 = load i8*, i8** %9
%22 = load i32, i32* %10
%23 = call i32 @kirk_CMD1(i8* %20, i8* %21, i32 %22, i32 1)
store i32 %23, i32* %12
%24 = load i32, i32* %12
%25 = icmp eq i32 %24, 3
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 2336, i32* %6
br label %49
27: ; preds = %19
%28 = load i32, i32* %12
store i32 %28, i32* %6
br label %49
29: ; preds = %5
%30 = load i8*, i8** %7
%31 = load i8*, i8** %9
%32 = load i32, i32* %10
%33 = call i32 @kirk_CMD4(i8* %30, i8* %31, i32 %32)
store i32 %33, i32* %6
br label %49
34: ; preds = %5
%35 = load i8*, i8** %7
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = call i32 @kirk_CMD7(i8* %35, i8* %36, i32 %37)
store i32 %38, i32* %6
br label %49
39: ; preds = %5
%40 = load i8*, i8** %9
%41 = load i32, i32* %10
%42 = call i32 @kirk_CMD10(i8* %40, i32 %41)
store i32 %42, i32* %6
br label %49
43: ; preds = %5
%44 = load i8*, i8** %7
%45 = load i8*, i8** %9
%46 = load i32, i32* %10
%47 = call i32 @kirk_CMD11(i8* %44, i8* %45, i32 %46)
store i32 %47, i32* %6
br label %49
48: ; preds = %5
store i32 -1, i32* %6
br label %49
49: ; preds = %48, %43, %39, %34, %29, %27, %26, %18
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
define i32 @sceUtilsBufferCopyWithRange(i8* %0, i32 %1, i8* %2, i32 %3, i32 %4) {
switch i32 %4, label %21 [
i32 1, label %6
i32 4, label %13
i32 7, label %15
i32 10, label %17
i32 11, label %19
]
6: ; preds = %5
%7 = and i32 %3, 15
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = tail call i32 @kirk_CMD1(i8* %0, i8* %2, i32 %3, i32 1)
%11 = icmp eq i32 %10, 3
%12 = select i1 %11, i32 2336, i32 %10
br label %21
13: ; preds = %5
%14 = tail call i32 @kirk_CMD4(i8* %0, i8* %2, i32 %3)
br label %21
15: ; preds = %5
%16 = tail call i32 @kirk_CMD7(i8* %0, i8* %2, i32 %3)
br label %21
17: ; preds = %5
%18 = tail call i32 @kirk_CMD10(i8* %2, i32 %3)
br label %21
19: ; preds = %5
%20 = tail call i32 @kirk_CMD11(i8* %0, i8* %2, i32 %3)
br label %21
21: ; preds = %5, %9, %6, %19, %17, %15, %13
%22 = phi i32 [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ 2314, %6 ], [ %12, %9 ], [ -1, %5 ]
ret i32 %22
}