#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;
    }
    length -= 20;
  } else {
    if (length < 24) {
      PEMerr(PEM_F_DO_PVK_HEADER, PEM_R_PVK_TOO_SHORT);
      return 0;
    }
    length -= 24;
    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     118a <do_PVK_header+0x6a>
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    1294 <do_PVK_header+0x174>
mov    -0x14(%rbp),%eax
sub    $0x14,%eax
mov    %eax,-0x14(%rbp)
jmp    1205 <do_PVK_header+0xe5>
cmpl   $0x18,-0x14(%rbp)
jae    11b7 <do_PVK_header+0x97>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <do_PVK_header+0x174>
mov    -0x14(%rbp),%eax
sub    $0x18,%eax
mov    %eax,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    $0xb0b5f11e,%ecx
cmp    %rcx,%rax
je     1200 <do_PVK_header+0xe0>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <do_PVK_header+0x174>
jmp    1205 <do_PVK_header+0xe5>
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     1282 <do_PVK_header+0x162>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1282 <do_PVK_header+0x162>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    1294 <do_PVK_header+0x174>
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 %29
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 %70
26: ; preds = %19
%27 = load i32, i32* %8
%28 = sub i32 %27, 20
store i32 %28, i32* %8
br label %48
29: ; preds = %5
%30 = load i32, i32* %8
%31 = icmp ult i32 %30, 24
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* @PEM_F_DO_PVK_HEADER
%34 = load i32, i32* @PEM_R_PVK_TOO_SHORT
%35 = call i32 @PEMerr(i32 %33, i32 %34)
store i32 0, i32* %6
br label %70
36: ; preds = %29
%37 = load i32, i32* %8
%38 = sub i32 %37, 24
store i32 %38, i32* %8
%39 = call i32 @read_ledword(i8** %12)
store i32 %39, i32* %13
%40 = load i32, i32* %13
%41 = zext i32 %40 to i64
%42 = icmp ne i64 %41, 2964713758
br i1 %42, label %43, label %47
43: ; preds = %36
%44 = load i32, i32* @PEM_F_DO_PVK_HEADER
%45 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%46 = call i32 @PEMerr(i32 %44, i32 %45)
store i32 0, i32* %6
br label %70
47: ; preds = %36
br label %48
48: ; preds = %47, %26
%49 = load i8*, i8** %12
%50 = getelementptr inbounds i8, i8* %49, i64 4
store i8* %50, i8** %12
%51 = call i32 @read_ledword(i8** %12)
%52 = call i32 @read_ledword(i8** %12)
store i32 %52, i32* %14
%53 = call i32 @read_ledword(i8** %12)
%54 = load i32*, i32** %10
store i32 %53, i32* %54
%55 = call i32 @read_ledword(i8** %12)
%56 = load i32*, i32** %11
store i32 %55, i32* %56
%57 = load i32, i32* %14
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %48
%60 = load i32*, i32** %10
%61 = load i32, i32* %60
%62 = icmp ne i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = load i32, i32* @PEM_F_DO_PVK_HEADER
%65 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%66 = call i32 @PEMerr(i32 %64, i32 %65)
store i32 0, i32* %6
br label %70
67: ; preds = %59, %48
%68 = load i8*, i8** %12
%69 = load i8**, i8*** %7
store i8* %68, i8** %69
store i32 1, i32* %6
br label %70
70: ; preds = %67, %63, %43, %32, %22
%71 = load i32, i32* %6
ret i32 %71
}

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
}