#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 /*<<< orphan*/ PEM_F_DO_PVK_HEADER;
int /*<<< orphan*/ PEM_R_BAD_MAGIC_NUMBER;
int /*<<< orphan*/ PEM_R_INCONSISTENT_HEADER;
int /*<<< orphan*/ PEM_R_PVK_TOO_SHORT;
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned int read_ledword(unsigned char const **);
int do_PVK_header(const unsigned char **in, unsigned int length, int skip_magic,
                  unsigned int *psaltlen, unsigned int *pkeylen) {
  const unsigned char *p = *in;
  unsigned int pvk_magic, is_encrypted;
  if (skip_magic) {
    if (length < 20) {
      PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);
      return 0;
    }
  } else {
    if (length < 24) {
      PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);
      return 0;
    }
    pvk_magic = read_ledword(&p);
    if (pvk_magic != 0xb0b5f11eL) {
      PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_BAD_MAGIC_NUMBER);
      return 0;
    }
  }
  p += 4;
  read_ledword(&p);
  is_encrypted = read_ledword(&p);
  *psaltlen = read_ledword(&p);
  *pkeylen = read_ledword(&p);
  if (is_encrypted && !*psaltlen) {
    PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_INCONSISTENT_HEADER);
    return 0;
  }
  *in = p;
  return 1;
}


x86 assembly (clang, -O0):
<do_PVK_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1181 <do_PVK_header+0x61>
cmpl   $0x14,-0x14(%rbp)
jae    117c <do_PVK_header+0x5c>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <do_PVK_header+0x162>
jmp    11f3 <do_PVK_header+0xd3>
cmpl   $0x18,-0x14(%rbp)
jae    11ae <do_PVK_header+0x8e>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <do_PVK_header+0x162>
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xb0b5f11e,%ecx
cmp    %rcx,%rax
je     11ee <do_PVK_header+0xce>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <do_PVK_header+0x162>
jmp    11f3 <do_PVK_header+0xd3>
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x38(%rbp)
je     1270 <do_PVK_header+0x150>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1270 <do_PVK_header+0x150>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1282 <do_PVK_header+0x162>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_PVK_header>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdi,%rbx
mov    (%rdi),%rax
mov    %rax,0x8(%rsp)
test   %edx,%edx
je     1148 <do_PVK_header+0x28>
cmp    $0x13,%esi
jbe    114d <do_PVK_header+0x2d>
jmp    117e <do_PVK_header+0x5e>
cmp    $0x17,%esi
ja     1168 <do_PVK_header+0x48>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
xor    %eax,%eax
jmp    11cb <do_PVK_header+0xab>
lea    0x8(%rsp),%rdi
call   1030 <read_ledword@plt>
cmp    $0xb0b5f11e,%eax
jne    11d8 <do_PVK_header+0xb8>
mov    0x8(%rsp),%rax
add    $0x4,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%r12
mov    %r12,%rdi
call   1030 <read_ledword@plt>
mov    %r12,%rdi
call   1030 <read_ledword@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1030 <read_ledword@plt>
mov    %eax,(%r14)
mov    %r12,%rdi
call   1030 <read_ledword@plt>
mov    %eax,(%r15)
test   %ebp,%ebp
je     11be <do_PVK_header+0x9e>
cmpl   $0x0,(%r14)
je     11ed <do_PVK_header+0xcd>
mov    0x8(%rsp),%rax
mov    %rax,(%rbx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2df8(%rip),%rax
jmp    115d <do_PVK_header+0x3d>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
jmp    115d <do_PVK_header+0x3d>

LLVM IR (-O0):
@PEM_F_DO_PVK_HEADER = global i32 0
@PEM_R_PVK_TOO_SHORT = global i32 0
@PEM_R_BAD_MAGIC_NUMBER = global i32 0
@PEM_R_INCONSISTENT_HEADER = global i32 0
define i32 @do_PVK_header(i8** %0, i32 %1, i32 %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8** %0, i8*** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32* %3, i32** %10
store i32* %4, i32** %11
%15 = load i8**, i8*** %7
%16 = load i8*, i8** %15
store i8* %16, i8** %12
%17 = load i32, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %5
%20 = load i32, i32* %8
%21 = icmp ult i32 %20, 20
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @PEM_F_DO_PVK_HEADER
%24 = load i32, i32* @PEM_R_PVK_TOO_SHORT
%25 = call i32 @PEMerr(i32 %23, i32 %24)
store i32 0, i32* %6
br label %66
26: ; preds = %19
br label %44
27: ; preds = %5
%28 = load i32, i32* %8
%29 = icmp ult i32 %28, 24
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @PEM_F_DO_PVK_HEADER
%32 = load i32, i32* @PEM_R_PVK_TOO_SHORT
%33 = call i32 @PEMerr(i32 %31, i32 %32)
store i32 0, i32* %6
br label %66
34: ; preds = %27
%35 = call i32 @read_ledword(i8** %12)
store i32 %35, i32* %13
%36 = load i32, i32* %13
%37 = zext i32 %36 to i64
%38 = icmp ne i64 %37, 2964713758
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i32, i32* @PEM_F_DO_PVK_HEADER
%41 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%42 = call i32 @PEMerr(i32 %40, i32 %41)
store i32 0, i32* %6
br label %66
43: ; preds = %34
br label %44
44: ; preds = %43, %26
%45 = load i8*, i8** %12
%46 = getelementptr inbounds i8, i8* %45, i64 4
store i8* %46, i8** %12
%47 = call i32 @read_ledword(i8** %12)
%48 = call i32 @read_ledword(i8** %12)
store i32 %48, i32* %14
%49 = call i32 @read_ledword(i8** %12)
%50 = load i32*, i32** %10
store i32 %49, i32* %50
%51 = call i32 @read_ledword(i8** %12)
%52 = load i32*, i32** %11
store i32 %51, i32* %52
%53 = load i32, i32* %14
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %44
%56 = load i32*, i32** %10
%57 = load i32, i32* %56
%58 = icmp ne i32 %57, 0
br i1 %58, label %63, label %59
59: ; preds = %55
%60 = load i32, i32* @PEM_F_DO_PVK_HEADER
%61 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%62 = call i32 @PEMerr(i32 %60, i32 %61)
store i32 0, i32* %6
br label %66
63: ; preds = %55, %44
%64 = load i8*, i8** %12
%65 = load i8**, i8*** %7
store i8* %64, i8** %65
store i32 1, i32* %6
br label %66
66: ; preds = %63, %59, %39, %30, %22
%67 = load i32, i32* %6
ret i32 %67
}

LLVM IR (-O2):
@PEM_F_DO_PVK_HEADER = global i32 0
@PEM_R_PVK_TOO_SHORT = global i32 0
@PEM_R_BAD_MAGIC_NUMBER = global i32 0
@PEM_R_INCONSISTENT_HEADER = global i32 0
define i32 @do_PVK_header(i8** nocapture %0, i32 %1, i32 %2, i32* nocapture %3, i32* nocapture writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = load i8*, i8** %0
store i8* %8, i8** %6
%9 = icmp eq i32 %2, 0
br i1 %9, label %16, label %10
10: ; preds = %5
%11 = icmp ult i32 %1, 20
br i1 %11, label %12, label %31
12: ; preds = %10
%13 = load i32, i32* @PEM_F_DO_PVK_HEADER
%14 = load i32, i32* @PEM_R_PVK_TOO_SHORT
%15 = tail call i32 @PEMerr(i32 %13, i32 %14)
br label %48
16: ; preds = %5
%17 = icmp ult i32 %1, 24
br i1 %17, label %18, label %22
18: ; preds = %16
%19 = load i32, i32* @PEM_F_DO_PVK_HEADER
%20 = load i32, i32* @PEM_R_PVK_TOO_SHORT
%21 = tail call i32 @PEMerr(i32 %19, i32 %20)
br label %48
22: ; preds = %16
%23 = call i32 @read_ledword(i8** %6)
%24 = icmp eq i32 %23, -1330253538
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = load i8*, i8** %6
br label %31
27: ; preds = %22
%28 = load i32, i32* @PEM_F_DO_PVK_HEADER
%29 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%30 = call i32 @PEMerr(i32 %28, i32 %29)
br label %48
31: ; preds = %25, %10
%32 = phi i8* [ %26, %25 ], [ %8, %10 ]
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %6
%34 = call i32 @read_ledword(i8** %6)
%35 = call i32 @read_ledword(i8** %6)
%36 = call i32 @read_ledword(i8** %6)
store i32 %36, i32* %3
%37 = call i32 @read_ledword(i8** %6)
store i32 %37, i32* %4
%38 = icmp eq i32 %35, 0
br i1 %38, label %46, label %39
39: ; preds = %31
%40 = load i32, i32* %3
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32, i32* @PEM_F_DO_PVK_HEADER
%44 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%45 = call i32 @PEMerr(i32 %43, i32 %44)
br label %48
46: ; preds = %39, %31
%47 = load i8*, i8** %6
store i8* %47, i8** %0
br label %48
48: ; preds = %46, %42, %27, %18, %12
%49 = phi i32 [ 0, %12 ], [ 1, %46 ], [ 0, %42 ], [ 0, %18 ], [ 0, %27 ]
ret i32 %49
}