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

/* Variables and functions */
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ NID_commonName;
int /*<<< orphan*/ OPENSSL_free(unsigned char *);
int /*<<< orphan*/ *PEM_read_bio_X509(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ X509_NAME_get_text_by_NID(int /*<<< orphan*/ *,
                                             int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ *X509_get_subject_name(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int i2d_X509(int /*<<< orphan*/ *, unsigned char **);
int /*<<< orphan*/ stderr;
int process_x509_pem(BIO *in_bp, BIO *out_bp) {
  X509 *x;
  int cert_count = 0;
  while (x = PEM_read_bio_X509(in_bp, NULL, NULL, NULL)) {
    unsigned char *cert = NULL;
    int cert_len;
    X509_NAME *cert_subject_name;
    char cert_cn[256];
    int i;
    cert_len = i2d_X509(x, &cert);
    if (cert_len < 0) {
      fprintf(stderr, "i2d_X509 failed\n");
      return 1;
    }
    cert_subject_name = X509_get_subject_name(x);
    X509_NAME_get_text_by_NID(cert_subject_name, NID_commonName, cert_cn,
                              sizeof(cert_cn));
    if (cert_count) {
      BIO_printf(out_bp, ",");
    }
    BIO_printf(out_bp, " \\\n    ");
    BIO_printf(out_bp, "/* CN = '%s', %d bytes */ \\\n    ", cert_cn, cert_len);
    for (i = 0; i < cert_len - 1; i++) {
      BIO_printf(out_bp, "0x%02X, ", cert[i]);
      if (i && (i + 1) % 16 == 0) {
        BIO_printf(out_bp, "\\\n    ");
      }
    }
    BIO_printf(out_bp, "0x%02X", cert[i]);
    cert_count++;
    OPENSSL_free(cert);
  }
  return (cert_count != 0) ? 0 : 1;
}


x86 assembly (clang, -O0):
<process_x509_pem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%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   1090 <PEM_read_bio_X509@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     132c <process_x509_pem+0x1bc>
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1040 <i2d_X509@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    11ee <process_x509_pem+0x7e>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    133f <process_x509_pem+0x1cf>
mov    -0x20(%rbp),%rdi
call   1050 <X509_get_subject_name@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    -0x140(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <X509_NAME_get_text_by_NID@plt>
cmpl   $0x0,-0x24(%rbp)
je     1235 <process_x509_pem+0xc5>
mov    -0x18(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x140(%rbp),%rdx
mov    -0x34(%rbp),%ecx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
movl   $0x0,-0x144(%rbp)
mov    -0x144(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12f4 <process_x509_pem+0x184>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x144(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
cmpl   $0x0,-0x144(%rbp)
je     12db <process_x509_pem+0x16b>
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12db <process_x509_pem+0x16b>
mov    -0x18(%rbp),%rdi
lea    0xd59(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
jmp    12e0 <process_x509_pem+0x170>
mov    -0x144(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x144(%rbp)
jmp    126d <process_x509_pem+0xfd>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x144(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1060 <BIO_printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1080 <OPENSSL_free@plt>
jmp    118a <process_x509_pem+0x1a>
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    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_x509_pem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <PEM_read_bio_X509@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     131e <process_x509_pem+0x1ae>
mov    %rsp,%rbp
mov    0x8(%rsp),%r13
xor    %r14d,%r14d
jmp    11f2 <process_x509_pem+0x82>
nopl   (%rax)
xor    %eax,%eax
mov    (%rsp),%rcx
movzbl (%rcx,%rax,1),%edx
mov    %r15,%rdi
lea    0xe79(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
add    $0x1,%r14d
mov    (%rsp),%rdi
call   1080 <OPENSSL_free@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1090 <PEM_read_bio_X509@plt>
mov    %rax,%r13
test   %rax,%rax
je     131e <process_x509_pem+0x1ae>
movq   $0x0,(%rsp)
mov    %r13,%rdi
mov    %rbp,%rsi
call   1040 <i2d_X509@plt>
test   %eax,%eax
js     132b <process_x509_pem+0x1bb>
mov    %eax,%r12d
mov    %r13,%rdi
call   1050 <X509_get_subject_name@plt>
mov    0x2dc1(%rip),%rcx
mov    (%rcx),%esi
mov    %rax,%rdi
lea    0x10(%rsp),%rdx
mov    $0x100,%ecx
call   1030 <X509_NAME_get_text_by_NID@plt>
test   %r14d,%r14d
je     1249 <process_x509_pem+0xd9>
mov    %r15,%rdi
lea    0xdcf(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
mov    %r15,%rdi
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
mov    %r15,%rdi
lea    0xdaf(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r12d,%ecx
xor    %eax,%eax
call   1060 <BIO_printf@plt>
cmp    $0x2,%r12d
jb     11b0 <process_x509_pem+0x40>
add    $0xffffffff,%r12d
mov    (%rsp),%rax
movzbl (%rax),%edx
mov    %r15,%rdi
lea    0xda2(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
mov    $0x1,%eax
cmp    $0x1,%r12d
je     11b2 <process_x509_pem+0x42>
mov    %rbx,%r13
mov    $0x1,%ebp
sub    %r12,%rbp
mov    $0x2,%ebx
jmp    12d2 <process_x509_pem+0x162>
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
je     1310 <process_x509_pem+0x1a0>
mov    (%rsp),%rax
movzbl -0x1(%rax,%rbx,1),%edx
mov    %r15,%rdi
lea    0xd4f(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
test   $0xf,%bl
jne    12c0 <process_x509_pem+0x150>
mov    %r15,%rdi
lea    0xd32(%rip),%rsi
xor    %eax,%eax
call   1060 <BIO_printf@plt>
jmp    12c0 <process_x509_pem+0x150>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rax
mov    %r13,%rbx
mov    %rsp,%rbp
jmp    11b2 <process_x509_pem+0x42>
xor    %eax,%eax
cmpq   $0x0,0x8(%rsp)
sete   %al
jmp    1345 <process_x509_pem+0x1d5>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xcc5(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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