#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_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*/ PEMerror(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) {
      PEMerror(PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
      return 0;
    }
    *pispub = 1;
  } else if (*p == 0x7) {
    if (*pispub == 1) {
      PEMerror(PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
      return 0;
    }
    *pispub = 0;
  } else
    return 0;
  p++;
  if (*p++ != 0x2) {
    PEMerror(PEM_R_BAD_VERSION_NUMBER);
    return 0;
  }
  p += 6;
  *pmagic = read_ledword(&p);
  *pbitlen = read_ledword(&p);
  if (*pbitlen > 65536) {
    PEMerror(PEM_R_INCONSISTENT_HEADER);
    return 0;
  }
  *pisdss = 0;
  switch (*pmagic) {
  case 0x31535344L:
    *pisdss = 1;
  case 0x31415352L:
    if (*pispub == 0) {
      PEMerror(PEM_R_EXPECTING_PRIVATE_KEY_BLOB);
      return 0;
    }
    break;
  case 0x32535344L:
    *pisdss = 1;
  case 0x32415352L:
    if (*pispub == 1) {
      PEMerror(PEM_R_EXPECTING_PUBLIC_KEY_BLOB);
      return 0;
    }
    break;
  default:
    PEMerror(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    138a <do_blob_header+0x26a>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x6,%eax
jne    11a6 <do_blob_header+0x86>
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1197 <do_blob_header+0x77>
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
mov    -0x38(%rbp),%rax
movl   $0x1,(%rax)
jmp    11fd <do_blob_header+0xdd>
mov    -0x40(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7,%eax
jne    11ec <do_blob_header+0xcc>
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jne    11dd <do_blob_header+0xbd>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
jmp    11f8 <do_blob_header+0xd8>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
jmp    11fd <do_blob_header+0xdd>
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     123e <do_blob_header+0x11e>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
mov    -0x40(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rdi
call   1040 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    -0x40(%rbp),%rdi
call   1040 <read_ledword@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0x10000,(%rax)
jbe    1296 <do_blob_header+0x176>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
sub    $0x31415352,%eax
je     12fc <do_blob_header+0x1dc>
jmp    12b9 <do_blob_header+0x199>
mov    -0x44(%rbp),%eax
sub    $0x31535344,%eax
je     12f2 <do_blob_header+0x1d2>
jmp    12cc <do_blob_header+0x1ac>
mov    -0x44(%rbp),%eax
sub    $0x32415352,%eax
je     1332 <do_blob_header+0x212>
jmp    12df <do_blob_header+0x1bf>
mov    -0x44(%rbp),%eax
sub    $0x32535344,%eax
je     1328 <do_blob_header+0x208>
jmp    135e <do_blob_header+0x23e>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1323 <do_blob_header+0x203>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
jmp    1378 <do_blob_header+0x258>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%rax
cmpl   $0x1,(%rax)
jne    1359 <do_blob_header+0x239>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0x0,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
jmp    1378 <do_blob_header+0x258>
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138a <do_blob_header+0x26a>
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     11c9 <do_blob_header+0xa9>
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     1169 <do_blob_header+0x49>
cmp    $0x6,%cl
jne    11c9 <do_blob_header+0xa9>
mov    $0x1,%ecx
cmpl   $0x0,0x0(%rbp)
jne    1184 <do_blob_header+0x64>
mov    0x2e61(%rip),%rax
jmp    11c2 <do_blob_header+0xa2>
xor    %ecx,%ecx
cmpl   $0x1,0x0(%rbp)
jne    1184 <do_blob_header+0x64>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
xor    %r14d,%r14d
jmp    11c9 <do_blob_header+0xa9>
mov    %ecx,0x0(%rbp)
cmpb   $0x2,0x1(%rax)
jne    11bb <do_blob_header+0x9b>
add    $0x8,%rax
mov    %rax,(%rsp)
mov    %rsp,%rdi
call   1040 <read_ledword@plt>
mov    %eax,0x0(%r13)
mov    %rsp,%rdi
call   1040 <read_ledword@plt>
mov    %eax,(%rbx)
cmp    $0x10001,%eax
jb     11db <do_blob_header+0xbb>
mov    0x2e1f(%rip),%rax
jmp    11c2 <do_blob_header+0xa2>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@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     120d <do_blob_header+0xed>
cmp    $0x31415352,%eax
je     1202 <do_blob_header+0xe2>
cmp    $0x31535344,%eax
jne    1241 <do_blob_header+0x121>
movl   $0x1,(%r15)
cmpl   $0x0,0x0(%rbp)
jne    1231 <do_blob_header+0x111>
jmp    1160 <do_blob_header+0x40>
cmp    $0x32415352,%eax
je     1222 <do_blob_header+0x102>
cmp    $0x32535344,%eax
jne    1241 <do_blob_header+0x121>
movl   $0x1,(%r15)
cmpl   $0x1,0x0(%rbp)
jne    1231 <do_blob_header+0x111>
mov    0x2d91(%rip),%rax
jmp    11c2 <do_blob_header+0xa2>
mov    (%rsp),%rax
mov    %rax,(%r12)
mov    $0x1,%r14d
jmp    11c9 <do_blob_header+0xa9>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1030 <PEMerror@plt>
mov    $0xffffffff,%r14d
jmp    11c9 <do_blob_header+0xa9>

LLVM IR (-O0):
@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 %104
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 %34
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 %32
29: ; preds = %25
%30 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%31 = call i32 @PEMerror(i32 %30)
store i32 0, i32* %7
br label %104
32: ; preds = %25
%33 = load i32*, i32** %13
store i32 1, i32* %33
br label %50
34: ; preds = %20
%35 = load i8*, i8** %14
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 7
br i1 %38, label %39, label %48
39: ; preds = %34
%40 = load i32*, i32** %13
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%45 = call i32 @PEMerror(i32 %44)
store i32 0, i32* %7
br label %104
46: ; preds = %39
%47 = load i32*, i32** %13
store i32 0, i32* %47
br label %49
48: ; preds = %34
store i32 0, i32* %7
br label %104
49: ; preds = %46
br label %50
50: ; preds = %49, %32
%51 = load i8*, i8** %14
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %14
%53 = load i8*, i8** %14
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %14
%55 = load i8, i8* %53
%56 = zext i8 %55 to i32
%57 = icmp ne i32 %56, 2
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* @PEM_R_BAD_VERSION_NUMBER
%60 = call i32 @PEMerror(i32 %59)
store i32 0, i32* %7
br label %104
61: ; preds = %50
%62 = load i8*, i8** %14
%63 = getelementptr inbounds i8, i8* %62, i64 6
store i8* %63, i8** %14
%64 = call i32 @read_ledword(i8** %14)
%65 = load i32*, i32** %10
store i32 %64, i32* %65
%66 = call i32 @read_ledword(i8** %14)
%67 = load i32*, i32** %11
store i32 %66, i32* %67
%68 = load i32*, i32** %11
%69 = load i32, i32* %68
%70 = icmp ugt i32 %69, 65536
br i1 %70, label %71, label %74
71: ; preds = %61
%72 = load i32, i32* @PEM_R_INCONSISTENT_HEADER
%73 = call i32 @PEMerror(i32 %72)
store i32 0, i32* %7
br label %104
74: ; preds = %61
%75 = load i32*, i32** %12
store i32 0, i32* %75
%76 = load i32*, i32** %10
%77 = load i32, i32* %76
switch i32 %77, label %98 [
i32 827544388, label %78
i32 826364754, label %80
i32 844321604, label %88
i32 843141970, label %90
]
78: ; preds = %74
%79 = load i32*, i32** %12
store i32 1, i32* %79
br label %80
80: ; preds = %74, %78
%81 = load i32*, i32** %13
%82 = load i32, i32* %81
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = load i32, i32* @PEM_R_EXPECTING_PRIVATE_KEY_BLOB
%86 = call i32 @PEMerror(i32 %85)
store i32 0, i32* %7
br label %104
87: ; preds = %80
br label %101
88: ; preds = %74
%89 = load i32*, i32** %12
store i32 1, i32* %89
br label %90
90: ; preds = %74, %88
%91 = load i32*, i32** %13
%92 = load i32, i32* %91
%93 = icmp eq i32 %92, 1
br i1 %93, label %94, label %97
94: ; preds = %90
%95 = load i32, i32* @PEM_R_EXPECTING_PUBLIC_KEY_BLOB
%96 = call i32 @PEMerror(i32 %95)
store i32 0, i32* %7
br label %104
97: ; preds = %90
br label %101
98: ; preds = %74
%99 = load i32, i32* @PEM_R_BAD_MAGIC_NUMBER
%100 = call i32 @PEMerror(i32 %99)
store i32 -1, i32* %7
br label %104
101: ; preds = %97, %87
%102 = load i8*, i8** %14
%103 = load i8**, i8*** %8
store i8* %102, i8** %103
store i32 1, i32* %7
br label %104
104: ; preds = %101, %98, %94, %84, %71, %58, %48, %43, %29, %19
%105 = load i32, i32* %7
ret i32 %105
}

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