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

/* Variables and functions */
size_t decode(int /*<<< orphan*/ *, unsigned int *);
scalar_t__ memcmp(int /*<<< orphan*/ *, char *, int);
int patch_get_input_size(uint8_t *patch, size_t patch_size,
                         size_t *input_size) {
  unsigned patch_offset;
  size_t expected_data_size;
  patch_offset = 0;
  if (patch_size < 4)
    return -1;
  if ((memcmp(patch, "UPS1", 4) == 0) || (memcmp(patch, "BPS1", 4) == 0)) {
    patch_offset += 4;
    expected_data_size = decode(patch, &patch_offset);
    if (input_size)
      *input_size = expected_data_size;
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<patch_get_input_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x4,-0x18(%rbp)
jae    1152 <patch_get_input_size+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <patch_get_input_size+0xb3>
mov    -0x10(%rbp),%rdi
lea    0xea3(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
je     1190 <patch_get_input_size+0x70>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%rax
jne    11cc <patch_get_input_size+0xac>
mov    -0x24(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
call   1040 <decode@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c0 <patch_get_input_size+0xa0>
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11d3 <patch_get_input_size+0xb3>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patch_get_input_size>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
cmp    $0x4,%rsi
jb     1187 <patch_get_input_size+0x67>
mov    %rdx,%r14
mov    %rdi,%rbx
lea    0xec0(%rip),%rsi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
je     1168 <patch_get_input_size+0x48>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <memcmp@plt>
test   %rax,%rax
jne    1187 <patch_get_input_size+0x67>
movl   $0x4,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <decode@plt>
xor    %ebp,%ebp
test   %r14,%r14
je     1187 <patch_get_input_size+0x67>
mov    %rax,(%r14)
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"UPS1\00"
@.str.1 = [5 x i8] c"BPS1\00"
define i32 @patch_get_input_size(i32* %0, i64 %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i32
%9 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64* %2, i64** %7
store i32 0, i32* %8
%10 = load i64, i64* %6
%11 = icmp ult i64 %10, 4
br i1 %11, label %12, label %13
12: ; preds = %3
store i32 -1, i32* %4
br label %33
13: ; preds = %3
%14 = load i32*, i32** %5
%15 = call i64 @memcmp(i32* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32*, i32** %5
%19 = call i64 @memcmp(i32* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %17, %13
%22 = load i32, i32* %8
%23 = add i32 %22, 4
store i32 %23, i32* %8
%24 = load i32*, i32** %5
%25 = call i64 @decode(i32* %24, i32* %8)
store i64 %25, i64* %9
%26 = load i64*, i64** %7
%27 = icmp ne i64* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i64, i64* %9
%30 = load i64*, i64** %7
store i64 %29, i64* %30
br label %31
31: ; preds = %28, %21
store i32 0, i32* %4
br label %33
32: ; preds = %17
store i32 -1, i32* %4
br label %33
33: ; preds = %32, %31, %12
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"UPS1\00"
@.str.1 = [5 x i8] c"BPS1\00"
define i32 @patch_get_input_size(i32* %0, i64 %1, i64* writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp ult i64 %1, 4
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = tail call i64 @memcmp(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i64 @memcmp(i32* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10, %7
store i32 4, i32* %4
%14 = call i64 @decode(i32* %0, i32* %4)
%15 = icmp eq i64* %2, null
br i1 %15, label %17, label %16
16: ; preds = %13
store i64 %14, i64* %2
br label %17
17: ; preds = %10, %13, %16, %3
%18 = phi i32 [ -1, %3 ], [ 0, %16 ], [ 0, %13 ], [ -1, %10 ]
ret i32 %18
}