#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*/ 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);
  *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    139a <do_blob_header+0x27a>
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    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
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    0x2de5(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
jmp    120a <do_blob_header+0xea>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
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    0x2d7b(%rip),%rax
mov    (%rax),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
mov    -0x40(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
mov    %rdi,-0x50(%rbp)
call   1030 <read_ledword@plt>
mov    -0x50(%rbp),%rdi
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
call   1030 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x31415352,%eax
je     12f1 <do_blob_header+0x1d1>
jmp    12ae <do_blob_header+0x18e>
mov    -0x44(%rbp),%eax
sub    $0x31535344,%eax
je     12e7 <do_blob_header+0x1c7>
jmp    12c1 <do_blob_header+0x1a1>
mov    -0x44(%rbp),%eax
sub    $0x32415352,%eax
je     1330 <do_blob_header+0x210>
jmp    12d4 <do_blob_header+0x1b4>
mov    -0x44(%rbp),%eax
sub    $0x32535344,%eax
je     1326 <do_blob_header+0x206>
jmp    1365 <do_blob_header+0x245>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1321 <do_blob_header+0x201>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
mov    0x2cc2(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
jmp    1388 <do_blob_header+0x268>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1360 <do_blob_header+0x240>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0x0,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
jmp    1388 <do_blob_header+0x268>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
mov    0x2c73(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139a <do_blob_header+0x27a>
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     120b <do_blob_header+0xeb>
mov    %r9,%rbp
mov    %r8,%r15
mov    %rcx,%r13
mov    %rdx,%rbx
mov    %rdi,%r12
mov    (%rdi),%rax
mov    (%rax),%cl
cmp    $0x7,%cl
je     1179 <do_blob_header+0x59>
cmp    $0x6,%cl
jne    120b <do_blob_header+0xeb>
mov    $0x1,%ecx
cmpl   $0x0,0x0(%rbp)
jne    119d <do_blob_header+0x7d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e5c(%rip),%rax
jmp    1204 <do_blob_header+0xe4>
xor    %ecx,%ecx
cmpl   $0x1,0x0(%rbp)
jne    119d <do_blob_header+0x7d>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
xor    %r14d,%r14d
jmp    120b <do_blob_header+0xeb>
mov    %ecx,0x0(%rbp)
cmpb   $0x2,0x1(%rax)
jne    11f4 <do_blob_header+0xd4>
add    $0x8,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1030 <read_ledword@plt>
mov    %eax,(%rbx)
mov    %rsp,%rdi
call   1030 <read_ledword@plt>
mov    %eax,0x0(%r13)
movl   $0x0,(%r15)
mov    (%rbx),%eax
cmp    $0x32415351,%eax
jg     121d <do_blob_header+0xfd>
cmp    $0x31415352,%eax
je     11e9 <do_blob_header+0xc9>
cmp    $0x31535344,%eax
jne    125a <do_blob_header+0x13a>
movl   $0x1,(%r15)
cmpl   $0x0,0x0(%rbp)
jne    124a <do_blob_header+0x12a>
jmp    1164 <do_blob_header+0x44>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    0x2ddc(%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
cmp    $0x32415352,%eax
je     1232 <do_blob_header+0x112>
cmp    $0x32535344,%eax
jne    125a <do_blob_header+0x13a>
movl   $0x1,(%r15)
cmpl   $0x1,0x0(%rbp)
jne    124a <do_blob_header+0x12a>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    0x2d80(%rip),%rax
jmp    1204 <do_blob_header+0xe4>
mov    (%rsp),%rax
mov    %rax,(%r12)
mov    $0x1,%r14d
jmp    120b <do_blob_header+0xeb>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
call   1040 <PEMerr@plt>
mov    $0xffffffff,%r14d
jmp    120b <do_blob_header+0xeb>

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_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 %103
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 %103
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 %103
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 %103
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 %103
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** %12
store i32 0, i32* %71
%72 = load i32*, i32** %10
%73 = load i32, i32* %72
switch i32 %73, label %96 [
i32 827544388, label %74
i32 826364754, label %76
i32 844321604, label %85
i32 843141970, label %87
]
74: ; preds = %64
%75 = load i32*, i32** %12
store i32 1, i32* %75
br label %76
76: ; preds = %64, %74
%77 = load i32*, i32** %13
%78 = load i32, i32* %77
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %84
80: ; preds = %76
%81 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%82 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%83 = call i32 @PEMerr(i32 %81, i32 %82)
store i32 0, i32* %7
br label %103
84: ; preds = %76
br label %100
85: ; preds = %64
%86 = load i32*, i32** %12
store i32 1, i32* %86
br label %87
87: ; preds = %64, %85
%88 = load i32*, i32** %13
%89 = load i32, i32* %88
%90 = icmp eq i32 %89, 1
br i1 %90, label %91, label %95
91: ; preds = %87
%92 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%93 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%94 = call i32 @PEMerr(i32 %92, i32 %93)
store i32 0, i32* %7
br label %103
95: ; preds = %87
br label %100
96: ; preds = %64
%97 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%98 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%99 = call i32 @PEMerr(i32 %97, i32 %98)
store i32 -1, i32* %7
br label %103
100: ; preds = %95, %84
%101 = load i8*, i8** %14
%102 = load i8**, i8*** %8
store i8* %101, i8** %102
store i32 1, i32* %7
br label %103
103: ; preds = %100, %96, %91, %80, %60, %50, %44, %29, %19
%104 = load i32, i32* %7
ret i32 %104
}

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_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 %63, label %11
11: ; preds = %6
%12 = load i8, i8* %9
switch i8 %12, label %63 [
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 %63
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 %63
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 %63
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
store i32 0, i32* %4
%40 = load i32, i32* %2
switch i32 %40, label %57 [
i32 827544388, label %41
i32 826364754, label %42
i32 844321604, label %49
i32 843141970, label %50
]
41: ; preds = %36
store i32 1, i32* %4
br label %42
42: ; preds = %36, %41
%43 = load i32, i32* %5
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %61
45: ; preds = %42
%46 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%47 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%48 = call i32 @PEMerr(i32 %46, i32 %47)
br label %63
49: ; preds = %36
store i32 1, i32* %4
br label %50
50: ; preds = %36, %49
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%55 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%56 = call i32 @PEMerr(i32 %54, i32 %55)
br label %63
57: ; preds = %36
%58 = load i32, i32* @PEM_F_DO_BLOB_HEADER
%59 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%60 = call i32 @PEMerr(i32 %58, i32 %59)
br label %63
61: ; preds = %50, %42
%62 = load i8*, i8** %7
store i8* %62, i8** %0
br label %63
63: ; preds = %11, %6, %61, %57, %53, %45, %32, %23, %16
%64 = phi i32 [ 0, %16 ], [ 0, %32 ], [ -1, %57 ], [ 0, %53 ], [ 1, %61 ], [ 0, %45 ], [ 0, %23 ], [ 0, %6 ], [ 0, %11 ]
ret i32 %64
}