#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 uint8_t;
typedef int uint32_t;

/* Variables and functions */
scalar_t__ func_b1c_c(int *);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
uint32_t func_808_c(uint8_t *buf, uint8_t *scratch1, uint8_t *scratch2,
                    uint8_t *decrypted_ok) {
  int idx;
  *decrypted_ok = 0;
  if (func_b1c_c(buf + 4) != 0) {
    return 11;
  }
  *decrypted_ok = 1;
  memcpy(scratch2, buf, 296);
  idx = 906;
  memcpy(scratch1, &buf[idx], 5);
  idx += 5;
  memset(&scratch1[8], 0, 32);
  memset(&scratch1[12], 0, 32);
  memcpy(&scratch1[8], &buf[idx], 30);
  idx += 30;
  memcpy(&scratch1[12], &buf[idx], 30);
  idx += 30;
  memcpy(&scratch1[16], &buf[idx], 16);
  idx += 33;
  memcpy(&scratch1[49], &buf[idx], 21);
  if (scratch2[286] != 1 || scratch2[287] != 0) {
    return 24;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<func_808_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1030 <func_b1c_c@plt>
cmp    $0x0,%rax
je     1175 <func_808_c+0x45>
movl   $0xb,-0x4(%rbp)
jmp    12bd <func_808_c+0x18d>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x128,%edx
call   1050 <memcpy@plt>
movl   $0x38a,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x5,%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x30,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
add    $0x20,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1e,%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1e,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x30,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x1e,%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1e,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x40,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x21,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
add    $0xc4,%rdi
mov    -0x10(%rbp),%rsi
movslq -0x2c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    $0x15,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
cmpl   $0x1,0x478(%rax)
jne    12aa <func_808_c+0x17a>
mov    -0x20(%rbp),%rax
cmpl   $0x0,0x47c(%rax)
je     12b6 <func_808_c+0x186>
movl   $0x18,-0x4(%rbp)
jmp    12bd <func_808_c+0x18d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func_808_c>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movl   $0x0,(%rcx)
add    $0x10,%rdi
call   1030 <func_b1c_c@plt>
mov    %rax,%rcx
mov    $0xb,%eax
test   %rcx,%rcx
jne    1234 <func_808_c+0x104>
movl   $0x1,(%rbx)
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x128,%edx
call   1050 <memcpy@plt>
lea    0xe28(%r12),%rsi
mov    %r15,%rdi
mov    $0x5,%edx
call   1050 <memcpy@plt>
lea    0x20(%r15),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0x30(%r15),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0xe3c(%r12),%rsi
mov    %r13,%rdi
mov    $0x1e,%edx
call   1050 <memcpy@plt>
lea    0xeb4(%r12),%rsi
mov    %rbx,%rdi
mov    $0x1e,%edx
call   1050 <memcpy@plt>
lea    0x40(%r15),%rdi
lea    0xf2c(%r12),%rsi
mov    $0x10,%edx
call   1050 <memcpy@plt>
add    $0xc4,%r15
add    $0xfb0,%r12
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x15,%edx
call   1050 <memcpy@plt>
mov    $0x18,%eax
cmpl   $0x1,0x478(%r14)
01
jne    1234 <func_808_c+0x104>
mov    0x47c(%r14),%ecx
test   %ecx,%ecx
mov    $0x18,%eax
cmove  %ecx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @func_808_c(i32* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%11 = load i32*, i32** %9
store i32 0, i32* %11
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 4
%14 = call i64 @func_b1c_c(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 11, i32* %5
br label %81
17: ; preds = %4
%18 = load i32*, i32** %9
store i32 1, i32* %18
%19 = load i32*, i32** %8
%20 = load i32*, i32** %6
%21 = call i32 @memcpy(i32* %19, i32* %20, i32 296)
store i32 906, i32* %10
%22 = load i32*, i32** %7
%23 = load i32*, i32** %6
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = call i32 @memcpy(i32* %22, i32* %26, i32 5)
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 5
store i32 %29, i32* %10
%30 = load i32*, i32** %7
%31 = getelementptr inbounds i32, i32* %30, i64 8
%32 = call i32 @memset(i32* %31, i32 0, i32 32)
%33 = load i32*, i32** %7
%34 = getelementptr inbounds i32, i32* %33, i64 12
%35 = call i32 @memset(i32* %34, i32 0, i32 32)
%36 = load i32*, i32** %7
%37 = getelementptr inbounds i32, i32* %36, i64 8
%38 = load i32*, i32** %6
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
%42 = call i32 @memcpy(i32* %37, i32* %41, i32 30)
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 30
store i32 %44, i32* %10
%45 = load i32*, i32** %7
%46 = getelementptr inbounds i32, i32* %45, i64 12
%47 = load i32*, i32** %6
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
%51 = call i32 @memcpy(i32* %46, i32* %50, i32 30)
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 30
store i32 %53, i32* %10
%54 = load i32*, i32** %7
%55 = getelementptr inbounds i32, i32* %54, i64 16
%56 = load i32*, i32** %6
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i32, i32* %56, i64 %58
%60 = call i32 @memcpy(i32* %55, i32* %59, i32 16)
%61 = load i32, i32* %10
%62 = add nsw i32 %61, 33
store i32 %62, i32* %10
%63 = load i32*, i32** %7
%64 = getelementptr inbounds i32, i32* %63, i64 49
%65 = load i32*, i32** %6
%66 = load i32, i32* %10
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i32, i32* %65, i64 %67
%69 = call i32 @memcpy(i32* %64, i32* %68, i32 21)
%70 = load i32*, i32** %8
%71 = getelementptr inbounds i32, i32* %70, i64 286
%72 = load i32, i32* %71
%73 = icmp ne i32 %72, 1
br i1 %73, label %79, label %74
74: ; preds = %17
%75 = load i32*, i32** %8
%76 = getelementptr inbounds i32, i32* %75, i64 287
%77 = load i32, i32* %76
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %74, %17
store i32 24, i32* %5
br label %81
80: ; preds = %74
store i32 0, i32* %5
br label %81
81: ; preds = %80, %79, %16
%82 = load i32, i32* %5
ret i32 %82
}

LLVM IR (-O2):
define i32 @func_808_c(i32* %0, i32* %1, i32* %2, i32* nocapture writeonly %3) {
store i32 0, i32* %3
%5 = getelementptr inbounds i32, i32* %0, i64 4
%6 = tail call i64 @func_b1c_c(i32* %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %34
8: ; preds = %4
store i32 1, i32* %3
%9 = tail call i32 @memcpy(i32* %2, i32* %0, i32 296)
%10 = getelementptr inbounds i32, i32* %0, i64 906
%11 = tail call i32 @memcpy(i32* %1, i32* %10, i32 5)
%12 = getelementptr inbounds i32, i32* %1, i64 8
%13 = tail call i32 @memset(i32* %12, i32 0, i32 32)
%14 = getelementptr inbounds i32, i32* %1, i64 12
%15 = tail call i32 @memset(i32* %14, i32 0, i32 32)
%16 = getelementptr inbounds i32, i32* %0, i64 911
%17 = tail call i32 @memcpy(i32* %12, i32* %16, i32 30)
%18 = getelementptr inbounds i32, i32* %0, i64 941
%19 = tail call i32 @memcpy(i32* %14, i32* %18, i32 30)
%20 = getelementptr inbounds i32, i32* %1, i64 16
%21 = getelementptr inbounds i32, i32* %0, i64 971
%22 = tail call i32 @memcpy(i32* %20, i32* %21, i32 16)
%23 = getelementptr inbounds i32, i32* %1, i64 49
%24 = getelementptr inbounds i32, i32* %0, i64 1004
%25 = tail call i32 @memcpy(i32* %23, i32* %24, i32 21)
%26 = getelementptr inbounds i32, i32* %2, i64 286
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %34
29: ; preds = %8
%30 = getelementptr inbounds i32, i32* %2, i64 287
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 0, i32 24
br label %34
34: ; preds = %29, %8, %4
%35 = phi i32 [ 11, %4 ], [ 24, %8 ], [ %33, %29 ]
ret i32 %35
}