#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_BLOB_HEADER;
int /*<<< orphan*/ PEM_R_BAD_MAGIC_NUMBER;
int /*<<< orphan*/ PEM_R_BAD_VERSION_NUMBER;
int /*<<< orphan*/ PEM_R_EXPECTING_PRIVATE_KEY_BLOB;
int /*<<< orphan*/ PEM_R_EXPECTING_PUBLIC_KEY_BLOB;
int /*<<< orphan*/ PEM_R_INCONSISTENT_HEADER;
int /*<<< orphan*/ PEMerr(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned int read_ledword(unsigned char const **);
int do_blob_header(const unsigned char **in, unsigned int length,
                   unsigned int *pmagic, unsigned int *pbitlen, int *pisdss,
                   int *pispub) {
  const unsigned char *p = *in;
  if (length < 16)
    return 0;
  if (*p == 0x6) {
    if (*pispub == 0) {
      PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
      return 0;
    }
    *pispub = 1;
  } else if (*p == 0x7) {
    if (*pispub == 1) {
      PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
      return 0;
    }
    *pispub = 0;
  } else
    return 0;
  p++;
  if (*p++ != 0x2) {
    PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_VERSION_NUMBER);
    return 0;
  }
  p += 6;
  *pmagic = read_ledword(&p);
  *pbitlen = read_ledword(&p);
  if (*pbitlen > 65536) {
    PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_INCONSISTENT_HEADER);
    return 0;
  }
  *pisdss = 0;
  switch (*pmagic) {
  case 0x31535344L:
    *pisdss = 1;
  case 0x31415352L:
    if (*pispub == 0) {
      PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
      return 0;
    }
    break;
  case 0x32535344L:
    *pisdss = 1;
  case 0x32415352L:
    if (*pispub == 1) {
      PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
      return 0;
    }
    break;
  default:
    PEMerr(PEM_F_DO_BLOB_HEADER, PEM_R_BAD_MAGIC_NUMBER);
    return -1;
  }
  *in = p;
  return 1;
}


x86 assembly (clang, -O0):
<do_blob_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpl   $0x10,-0x14(%rbp)
jae    1160 <do_blob_header+0x40>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x6,%eax
jne    11af <do_blob_header+0x8f>
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11a0 <do_blob_header+0x80>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x38(%rbp),%rax
movl   $0x1,(%rax)
jmp    120f <do_blob_header+0xef>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7,%eax
jne    11fe <do_blob_header+0xde>
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jne    11ef <do_blob_header+0xcf>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
jmp    120a <do_blob_header+0xea>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
jmp    120f <do_blob_header+0xef>
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movzbl (%rax),%eax
cmp    $0x2,%eax
je     1259 <do_blob_header+0x139>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x40(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x40(%rbp),%rdi
call   1030 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x10000,(%rax)
jbe    12ba <do_blob_header+0x19a>
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x31415352,%eax
je     1320 <do_blob_header+0x200>
jmp    12dd <do_blob_header+0x1bd>
mov    -0x44(%rbp),%eax
sub    $0x31535344,%eax
je     1316 <do_blob_header+0x1f6>
jmp    12f0 <do_blob_header+0x1d0>
mov    -0x44(%rbp),%eax
sub    $0x32415352,%eax
je     135f <do_blob_header+0x23f>
jmp    1303 <do_blob_header+0x1e3>
mov    -0x44(%rbp),%eax
sub    $0x32535344,%eax
je     1355 <do_blob_header+0x235>
jmp    1394 <do_blob_header+0x274>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1350 <do_blob_header+0x230>
mov    0x2c7c(%rip),%rax
mov    (%rax),%edi
mov    0x2c8b(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
jmp    13b7 <do_blob_header+0x297>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jne    138f <do_blob_header+0x26f>
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
jmp    13b7 <do_blob_header+0x297>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
mov    0x2c44(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c9 <do_blob_header+0x2a9>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_blob_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r14d,%r14d
cmp    $0x10,%esi
jb     11f1 <do_blob_header+0xd1>
mov    %r9,%rbp
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rdi,%r12
mov    (%rdi),%rax
mov    (%rax),%cl
cmp    $0x7,%cl
je     1176 <do_blob_header+0x56>
cmp    $0x6,%cl
jne    11f1 <do_blob_header+0xd1>
mov    $0x1,%ecx
cmpl   $0x0,0x0(%rbp)
jne    119a <do_blob_header+0x7a>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    0x2e54(%rip),%rax
jmp    11ea <do_blob_header+0xca>
xor    %ecx,%ecx
cmpl   $0x1,0x0(%rbp)
jne    119a <do_blob_header+0x7a>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
xor    %r14d,%r14d
jmp    11f1 <do_blob_header+0xd1>
mov    %ecx,0x0(%rbp)
cmpb   $0x2,0x1(%rax)
jne    11da <do_blob_header+0xba>
add    $0x8,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1030 <read_ledword@plt>
mov    %eax,0x0(%r13)
mov    %rsp,%rdi
call   1030 <read_ledword@plt>
mov    %eax,(%rbx)
cmp    $0x10001,%eax
jb     1203 <do_blob_header+0xe3>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
jmp    11ea <do_blob_header+0xca>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movl   $0x0,(%r15)
mov    0x0(%r13),%eax
cmp    $0x32415351,%eax
jg     1235 <do_blob_header+0x115>
cmp    $0x31415352,%eax
je     122a <do_blob_header+0x10a>
cmp    $0x31535344,%eax
jne    1275 <do_blob_header+0x155>
movl   $0x1,(%r15)
cmpl   $0x0,0x0(%rbp)
jne    1262 <do_blob_header+0x142>
jmp    1164 <do_blob_header+0x44>
cmp    $0x32415352,%eax
je     124a <do_blob_header+0x12a>
cmp    $0x32535344,%eax
jne    1275 <do_blob_header+0x155>
movl   $0x1,(%r15)
cmpl   $0x1,0x0(%rbp)
jne    1262 <do_blob_header+0x142>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
mov    0x2d60(%rip),%rax
jmp    11ea <do_blob_header+0xca>
mov    (%rsp),%rax
mov    %rax,(%r12)
mov    $0x1,%r14d
jmp    11f1 <do_blob_header+0xd1>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
mov    $0xffffffff,%r14d
jmp    11f1 <do_blob_header+0xd1>

LLVM IR (-O0):
@PEM_F_DO_BLOB_HEADER = global i32 0
@PEM_R_EXPECTING_PRIVATE_KEY_BLOB = global i32 0
@PEM_R_EXPECTING_PUBLIC_KEY_BLOB = global i32 0
@PEM_R_BAD_VERSION_NUMBER = global i32 0
@PEM_R_INCONSISTENT_HEADER = global i32 0
@PEM_R_BAD_MAGIC_NUMBER = global i32 0
define i32 @do_blob_header(i8** %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i8*
store i8** %0, i8*** %8
store i32 %1, i32* %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%15 = load i8**, i8*** %8
%16 = load i8*, i8** %15
store i8* %16, i8** %14
%17 = load i32, i32* %9
%18 = icmp ult i32 %17, 16
br i1 %18, label %19, label %20
19: ; preds = %6
store i32 0, i32* %7
br label %111
20: ; preds = %6
%21 = load i8*, i8** %14
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 6
br i1 %24, label %25, label %35
25: ; preds = %20
%26 = load i32*, i32** %13
%27 = load i32, i32* %26
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%31 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%32 = call i32 @PEMerr(i32 %30, i32 %31)
store i32 0, i32* %7
br label %111
33: ; preds = %25
%34 = load i32*, i32** %13
store i32 1, i32* %34
br label %52
35: ; preds = %20
%36 = load i8*, i8** %14
%37 = load i8, i8* %36
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %38, 7
br i1 %39, label %40, label %50
40: ; preds = %35
%41 = load i32*, i32** %13
%42 = load i32, i32* %41
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%46 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%47 = call i32 @PEMerr(i32 %45, i32 %46)
store i32 0, i32* %7
br label %111
48: ; preds = %40
%49 = load i32*, i32** %13
store i32 0, i32* %49
br label %51
50: ; preds = %35
store i32 0, i32* %7
br label %111
51: ; preds = %48
br label %52
52: ; preds = %51, %33
%53 = load i8*, i8** %14
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %14
%55 = load i8*, i8** %14
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %14
%57 = load i8, i8* %55
%58 = zext i8 %57 to i32
%59 = icmp ne i32 %58, 2
br i1 %59, label %60, label %64
60: ; preds = %52
%61 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%62 = load i32, i32* @PEM_R_BAD_VERSION_NUMBER
%63 = call i32 @PEMerr(i32 %61, i32 %62)
store i32 0, i32* %7
br label %111
64: ; preds = %52
%65 = load i8*, i8** %14
%66 = getelementptr inbounds i8, i8* %65, i64 6
store i8* %66, i8** %14
%67 = call i32 @read_ledword(i8** %14)
%68 = load i32*, i32** %10
store i32 %67, i32* %68
%69 = call i32 @read_ledword(i8** %14)
%70 = load i32*, i32** %11
store i32 %69, i32* %70
%71 = load i32*, i32** %11
%72 = load i32, i32* %71
%73 = icmp ugt i32 %72, 65536
br i1 %73, label %74, label %78
74: ; preds = %64
%75 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%76 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%77 = call i32 @PEMerr(i32 %75, i32 %76)
store i32 0, i32* %7
br label %111
78: ; preds = %64
%79 = load i32*, i32** %12
store i32 0, i32* %79
%80 = load i32*, i32** %10
%81 = load i32, i32* %80
switch i32 %81, label %104 [
i32 827544388, label %82
i32 826364754, label %84
i32 844321604, label %93
i32 843141970, label %95
]
82: ; preds = %78
%83 = load i32*, i32** %12
store i32 1, i32* %83
br label %84
84: ; preds = %78, %82
%85 = load i32*, i32** %13
%86 = load i32, i32* %85
%87 = icmp eq i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %84
%89 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%90 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%91 = call i32 @PEMerr(i32 %89, i32 %90)
store i32 0, i32* %7
br label %111
92: ; preds = %84
br label %108
93: ; preds = %78
%94 = load i32*, i32** %12
store i32 1, i32* %94
br label %95
95: ; preds = %78, %93
%96 = load i32*, i32** %13
%97 = load i32, i32* %96
%98 = icmp eq i32 %97, 1
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%101 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%102 = call i32 @PEMerr(i32 %100, i32 %101)
store i32 0, i32* %7
br label %111
103: ; preds = %95
br label %108
104: ; preds = %78
%105 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%106 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%107 = call i32 @PEMerr(i32 %105, i32 %106)
store i32 -1, i32* %7
br label %111
108: ; preds = %103, %92
%109 = load i8*, i8** %14
%110 = load i8**, i8*** %8
store i8* %109, i8** %110
store i32 1, i32* %7
br label %111
111: ; preds = %108, %104, %99, %88, %74, %60, %50, %44, %29, %19
%112 = load i32, i32* %7
ret i32 %112
}

LLVM IR (-O2):
@PEM_F_DO_BLOB_HEADER = global i32 0
@PEM_R_EXPECTING_PRIVATE_KEY_BLOB = global i32 0
@PEM_R_EXPECTING_PUBLIC_KEY_BLOB = global i32 0
@PEM_R_BAD_VERSION_NUMBER = global i32 0
@PEM_R_INCONSISTENT_HEADER = global i32 0
@PEM_R_BAD_MAGIC_NUMBER = global i32 0
define i32 @do_blob_header(i8** nocapture %0, i32 %1, i32* nocapture %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture %5) {
%7 = alloca i8*
%8 = bitcast i8** %7 to i8*
%9 = load i8*, i8** %0
%10 = icmp ult i32 %1, 16
br i1 %10, label %69, label %11
11: ; preds = %6
%12 = load i8, i8* %9
switch i8 %12, label %69 [
i8 6, label %13
i8 7, label %20
]
13: ; preds = %11
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %13
%17 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%18 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%19 = tail call i32 @PEMerr(i32 %17, i32 %18)
br label %69
20: ; preds = %11
%21 = load i32, i32* %5
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%25 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%26 = tail call i32 @PEMerr(i32 %24, i32 %25)
br label %69
27: ; preds = %20, %13
%28 = phi i32 [ 1, %13 ], [ 0, %20 ]
store i32 %28, i32* %5
%29 = getelementptr inbounds i8, i8* %9, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 2
br i1 %31, label %36, label %32
32: ; preds = %27
%33 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%34 = load i32, i32* @PEM_R_BAD_VERSION_NUMBER
%35 = tail call i32 @PEMerr(i32 %33, i32 %34)
br label %69
36: ; preds = %27
%37 = getelementptr inbounds i8, i8* %9, i64 8
store i8* %37, i8** %7
%38 = call i32 @read_ledword(i8** %7)
store i32 %38, i32* %2
%39 = call i32 @read_ledword(i8** %7)
store i32 %39, i32* %3
%40 = icmp ugt i32 %39, 65536
br i1 %40, label %41, label %45
41: ; preds = %36
%42 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%43 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%44 = call i32 @PEMerr(i32 %42, i32 %43)
br label %69
45: ; preds = %36
store i32 0, i32* %4
%46 = load i32, i32* %2
switch i32 %46, label %63 [
i32 827544388, label %47
i32 826364754, label %48
i32 844321604, label %55
i32 843141970, label %56
]
47: ; preds = %45
store i32 1, i32* %4
br label %48
48: ; preds = %45, %47
%49 = load i32, i32* %5
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %67
51: ; preds = %48
%52 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%53 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%54 = call i32 @PEMerr(i32 %52, i32 %53)
br label %69
55: ; preds = %45
store i32 1, i32* %4
br label %56
56: ; preds = %45, %55
%57 = load i32, i32* %5
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %67
59: ; preds = %56
%60 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%61 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%62 = call i32 @PEMerr(i32 %60, i32 %61)
br label %69
63: ; preds = %45
%64 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%65 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%66 = call i32 @PEMerr(i32 %64, i32 %65)
br label %69
67: ; preds = %56, %48
%68 = load i8*, i8** %7
store i8* %68, i8** %0
br label %69
69: ; preds = %11, %6, %67, %63, %59, %51, %41, %32, %23, %16
%70 = phi i32 [ 0, %16 ], [ 0, %32 ], [ 0, %41 ], [ -1, %63 ], [ 0, %59 ], [ 1, %67 ], [ 0, %51 ], [ 0, %23 ], [ 0, %6 ], [ 0, %11 ]
ret i32 %70
}