#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 */
typedef int /*<<< orphan*/ EVP_PKEY;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int /*<<< orphan*/ *PEM_read_bio_PUBKEY(int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *,
                                        int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int i2d_PUBKEY(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ stderr;
int process_pubkey_pem(BIO *in_bp, BIO *out_bp) {
  EVP_PKEY *pkey;
  int cert_count = 0;
  while (pkey = PEM_read_bio_PUBKEY(in_bp, NULL, NULL, NULL)) {
    unsigned char *pkey_der = NULL;
    int pkey_der_len;
    int i;
    pkey_der_len = i2d_PUBKEY(pkey, &pkey_der);
    if (pkey_der_len < 0) {
      fprintf(stderr, "i2d_PUBKEY failed\n");
      return 1;
    }
    if (cert_count) {
      BIO_printf(out_bp, ",");
    }
    BIO_printf(out_bp, " \\\n    ");
    for (i = 0; i < pkey_der_len - 1; i++) {
      BIO_printf(out_bp, "0x%02X, ", pkey_der[i]);
      if (i && (i + 1) % 16 == 0) {
        BIO_printf(out_bp, "\\\n    ");
      }
    }
    BIO_printf(out_bp, "0x%02X", pkey_der[i]);
    cert_count++;
    OPENSSL_free(pkey_der);
  }
  return (cert_count != 0) ? 0 : 1;
}


x86 assembly (clang, -O0):
<process_pubkey_pem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <PEM_read_bio_PUBKEY@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12aa <process_pubkey_pem+0x15a>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <i2d_PUBKEY@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11cb <process_pubkey_pem+0x7b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12bd <process_pubkey_pem+0x16d>
cmpl   $0x0,-0x24(%rbp)
je     11e7 <process_pubkey_pem+0x97>
mov    -0x18(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1275 <process_pubkey_pem+0x125>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xdf5(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
cmpl   $0x0,-0x38(%rbp)
je     1262 <process_pubkey_pem+0x112>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1262 <process_pubkey_pem+0x112>
mov    -0x18(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
jmp    1267 <process_pubkey_pem+0x117>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1200 <process_pubkey_pem+0xb0>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x38(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xd9a(%rip),%rsi
mov    $0x0,%al
call   1030 <BIO_printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <OPENSSL_free@plt>
jmp    1167 <process_pubkey_pem+0x17>
mov    -0x24(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_pubkey_pem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <PEM_read_bio_PUBKEY@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     12d0 <process_pubkey_pem+0x180>
mov    %rsp,%r15
lea    0xe96(%rip),%rbp
mov    0x8(%rsp),%rax
xor    %r13d,%r13d
mov    %r14,0x10(%rsp)
jmp    11df <process_pubkey_pem+0x8f>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
mov    (%rsp),%rcx
movzbl (%rcx,%rax,1),%edx
mov    %rbx,%rdi
lea    0xe72(%rip),%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
add    $0x1,%r13d
mov    (%rsp),%rdi
call   1070 <OPENSSL_free@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <PEM_read_bio_PUBKEY@plt>
test   %rax,%rax
je     12d0 <process_pubkey_pem+0x180>
movq   $0x0,(%rsp)
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <i2d_PUBKEY@plt>
test   %eax,%eax
js     12dd <process_pubkey_pem+0x18d>
mov    %eax,%r12d
test   %r13d,%r13d
je     1213 <process_pubkey_pem+0xc3>
mov    %rbx,%rdi
lea    0xe07(%rip),%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
mov    %rbx,%rdi
lea    0xdf8(%rip),%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
cmp    $0x2,%r12d
jb     11a0 <process_pubkey_pem+0x50>
add    $0xffffffff,%r12d
mov    (%rsp),%rax
movzbl (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
mov    $0x1,%eax
cmp    $0x1,%r12d
je     11a2 <process_pubkey_pem+0x52>
mov    $0x1,%r14d
sub    %r12,%r14
mov    $0x2,%r15d
jmp    1282 <process_pubkey_pem+0x132>
cs nopw 0x0(%rax,%rax,1)
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
add    $0x1,%r15
cmp    $0x2,%rax
je     12c0 <process_pubkey_pem+0x170>
mov    (%rsp),%rax
movzbl -0x1(%rax,%r15,1),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
test   $0xf,%r15b
jne    1270 <process_pubkey_pem+0x120>
mov    %rbx,%rdi
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1030 <BIO_printf@plt>
jmp    1270 <process_pubkey_pem+0x120>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rax
mov    0x10(%rsp),%r14
mov    %rsp,%r15
jmp    11a2 <process_pubkey_pem+0x52>
xor    %eax,%eax
cmpq   $0x0,0x8(%rsp)
sete   %al
jmp    12f7 <process_pubkey_pem+0x1a7>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
lea    0xd13(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"i2d_PUBKEY failed\0A\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [8 x i8] c" \\\0A \00"
@.str.3 = [9 x i8] c"0x%02X, \00"
@.str.4 = [7 x i8] c"\\\0A \00"
@.str.5 = [7 x i8] c"0x%02X\00"
define i32 @process_pubkey_pem(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 0, i32* %7
br label %11
11: ; preds = %60, %2
%12 = load i32*, i32** %4
%13 = call i32* @PEM_read_bio_PUBKEY(i32* %12, i32* null, i32* null, i32* null)
store i32* %13, i32** %6
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %73
15: ; preds = %11
store i8* null, i8** %8
%16 = load i32*, i32** %6
%17 = call i32 @i2d_PUBKEY(i32* %16, i8** %8)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %78
23: ; preds = %15
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32*, i32** %5
%28 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
%30 = load i32*, i32** %5
%31 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %30, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %10
br label %32
32: ; preds = %57, %29
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = sub nsw i32 %34, 1
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %60
37: ; preds = %32
%38 = load i32*, i32** %5
%39 = load i8*, i8** %8
%40 = load i32, i32* %10
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %56
48: ; preds = %37
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
%51 = srem i32 %50, 16
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = load i32*, i32** %5
%55 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %54, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %56
56: ; preds = %53, %48, %37
br label %57
57: ; preds = %56
%58 = load i32, i32* %10
%59 = add nsw i32 %58, 1
store i32 %59, i32* %10
br label %32
60: ; preds = %32
%61 = load i32*, i32** %5
%62 = load i8*, i8** %8
%63 = load i32, i32* %10
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %61, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
%71 = load i8*, i8** %8
%72 = call i32 @OPENSSL_free(i8* %71)
br label %11
73: ; preds = %11
%74 = load i32, i32* %7
%75 = icmp ne i32 %74, 0
%76 = zext i1 %75 to i64
%77 = select i1 %75, i32 0, i32 1
store i32 %77, i32* %3
br label %78
78: ; preds = %73, %20
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"i2d_PUBKEY failed\0A\00"
@.str.1 = [2 x i8] c",\00"
@.str.2 = [8 x i8] c" \\\0A \00"
@.str.3 = [9 x i8] c"0x%02X, \00"
@.str.4 = [7 x i8] c"\\\0A \00"
@.str.5 = [7 x i8] c"0x%02X\00"
define i32 @process_pubkey_pem(i32* %0, i32* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32* @PEM_read_bio_PUBKEY(i32* %0, i32* null, i32* null, i32* null)
%6 = icmp eq i32* %5, null
br i1 %6, label %56, label %7
7: ; preds = %2, %44
%8 = phi i32* [ %54, %44 ], [ %5, %2 ]
%9 = phi i32 [ %51, %44 ], [ 0, %2 ]
store i8* null, i8** %3
%10 = call i32 @i2d_PUBKEY(i32* %8, i8** %3)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %58
15: ; preds = %7
%16 = icmp eq i32 %9, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp ugt i32 %10, 1
br i1 %21, label %22, label %44
22: ; preds = %19
%23 = add nsw i32 %10, -1
%24 = zext i32 %23 to i64
%25 = load i8*, i8** %3
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = icmp eq i32 %23, 1
br i1 %29, label %44, label %30
30: ; preds = %22, %42
%31 = phi i64 [ %37, %42 ], [ 1, %22 ]
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i64 %31
%34 = load i8, i8* %33
%35 = zext i8 %34 to i32
%36 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i64 %31, 1
%38 = and i64 %37, 15
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %30
%41 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %30, %40
%43 = icmp eq i64 %37, %24
br i1 %43, label %44, label %30
44: ; preds = %42, %22, %19
%45 = phi i64 [ 0, %19 ], [ 1, %22 ], [ %24, %42 ]
%46 = load i8*, i8** %3
%47 = getelementptr inbounds i8, i8* %46, i64 %45
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i32*, i8*, ...) @BIO_printf(i32* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %49)
%51 = add nuw nsw i32 %9, 1
%52 = load i8*, i8** %3
%53 = call i32 @OPENSSL_free(i8* %52)
%54 = call i32* @PEM_read_bio_PUBKEY(i32* %0, i32* null, i32* null, i32* null)
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %7
56: ; preds = %44, %2
%57 = zext i1 %6 to i32
br label %58
58: ; preds = %12, %56
%59 = phi i32 [ %57, %56 ], [ 1, %12 ]
ret i32 %59
}