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

/* Variables and functions */
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_mem_data(int /*<<< orphan*/ *, char **);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ X509V3_EXT_DEFAULT;
int /*<<< orphan*/ X509V3_EXT_print(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                    int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int strcmp(char *, char const *);
int compare_extension_printout(X509_EXTENSION *extension,
                               const char *expected_output) {
  BIO *text_buffer = NULL;
  char *actual_output = NULL;
  int result = 1;
  text_buffer = BIO_new(BIO_s_mem());
  if (text_buffer == NULL) {
    fprintf(stderr, "Unable to allocate buffer\n");
    goto end;
  }
  if (!X509V3_EXT_print(text_buffer, extension, X509V3_EXT_DEFAULT, 0)) {
    fprintf(stderr, "Failed to print extension\n");
    goto end;
  }
  if (BIO_write(text_buffer, "\0", 1) != 1) {
    fprintf(stderr, "Failed to append null terminator to extension text\n");
    goto end;
  }
  BIO_get_mem_data(text_buffer, &actual_output);
  result = strcmp(actual_output, expected_output);
  if (result != 0) {
    fprintf(stderr, "Expected SCT printout:\n%s\nActual SCT printout:\n%s\n",
            expected_output, actual_output);
  }
end:
  BIO_free(text_buffer);
  return result;
}


x86 assembly (clang, -O0):
<compare_extension_printout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
mov    $0x0,%al
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <compare_extension_printout+0x60>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a2 <compare_extension_printout+0x122>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1030 <X509V3_EXT_print@plt>
cmp    $0x0,%eax
jne    121d <compare_extension_printout+0x9d>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a2 <compare_extension_printout+0x122>
mov    -0x18(%rbp),%rdi
lea    0xe75(%rip),%rsi
mov    $0x1,%edx
call   1080 <BIO_write@plt>
cmp    $0x1,%eax
je     1257 <compare_extension_printout+0xd7>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdeb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a2 <compare_extension_printout+0x122>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <BIO_get_mem_data@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     129d <compare_extension_printout+0x11d>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a2 <compare_extension_printout+0x122>
mov    -0x18(%rbp),%rdi
call   1070 <BIO_free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_extension_printout>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1090 <BIO_s_mem@plt>
mov    %eax,%edi
call   1060 <BIO_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1222 <compare_extension_printout+0xa2>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %ecx,%ecx
call   1030 <X509V3_EXT_print@plt>
test   %eax,%eax
je     1234 <compare_extension_printout+0xb4>
lea    0xed1(%rip),%rsi
mov    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x1,%edx
call   1080 <BIO_write@plt>
cmp    $0x1,%eax
jne    1252 <compare_extension_printout+0xd2>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   10a0 <BIO_get_mem_data@plt>
mov    (%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     126b <compare_extension_printout+0xeb>
mov    %eax,%ebp
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    126d <compare_extension_printout+0xed>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdce(%rip),%rsi
jmp    1244 <compare_extension_printout+0xc4>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
lea    0xdd7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebp
jmp    126d <compare_extension_printout+0xed>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xdd4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    126d <compare_extension_printout+0xed>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1070 <BIO_free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Unable to allocate buffer\0A\00"
@X509V3_EXT_DEFAULT = global i32 0
@.str.1 = [27 x i8] c"Failed to print extension\0A\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [52 x i8] c"Failed to append null terminator to extension text\0A\00"
@.str.4 = [51 x i8] c"Expected SCT printout:\0A%s\0AActual SCT printout:\0A%s\0A\00"
define i32 @compare_extension_printout(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32* null, i32** %5
store i8* null, i8** %6
store i32 1, i32* %7
%8 = call i32 (...) @BIO_s_mem()
%9 = call i32* @BIO_new(i32 %8)
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %45
15: ; preds = %2
%16 = load i32*, i32** %5
%17 = load i32*, i32** %3
%18 = load i32, i32* @X509V3_EXT_DEFAULT
%19 = call i32 @X509V3_EXT_print(i32* %16, i32* %17, i32 %18, i32 0)
%20 = icmp ne i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %45
24: ; preds = %15
%25 = load i32*, i32** %5
%26 = call i32 @BIO_write(i32* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%27 = icmp ne i32 %26, 1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %45
31: ; preds = %24
%32 = load i32*, i32** %5
%33 = call i32 @BIO_get_mem_data(i32* %32, i8** %6)
%34 = load i8*, i8** %6
%35 = load i8*, i8** %4
%36 = call i32 @strcmp(i8* %34, i8* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %31
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %4
%42 = load i8*, i8** %6
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %41, i8* %42)
br label %44
44: ; preds = %39, %31
br label %45
45: ; preds = %44, %28, %21, %12
%46 = load i32*, i32** %5
%47 = call i32 @BIO_free(i32* %46)
%48 = load i32, i32* %7
ret i32 %48
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Unable to allocate buffer\0A\00"
@X509V3_EXT_DEFAULT = global i32 0
@.str.1 = [27 x i8] c"Failed to print extension\0A\00"
@.str.2 = [2 x i8] zeroinitializer
@.str.3 = [52 x i8] c"Failed to append null terminator to extension text\0A\00"
@.str.4 = [51 x i8] c"Expected SCT printout:\0A%s\0AActual SCT printout:\0A%s\0A\00"
define i32 @compare_extension_printout(i32* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = tail call i32 (...) @BIO_s_mem()
%6 = tail call i32* @BIO_new(i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %32
11: ; preds = %2
%12 = load i32, i32* @X509V3_EXT_DEFAULT
%13 = tail call i32 @X509V3_EXT_print(i32* %6, i32* %0, i32 %12, i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %32
18: ; preds = %11
%19 = tail call i32 @BIO_write(i32* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%20 = icmp eq i32 %19, 1
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.3, i64 0, i64 0))
br label %32
24: ; preds = %18
%25 = call i32 @BIO_get_mem_data(i32* %6, i8** %3)
%26 = load i8*, i8** %3
%27 = call i32 @strcmp(i8* dereferenceable(1) %26, i8* dereferenceable(1) %1)
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %26)
br label %32
32: ; preds = %24, %29, %21, %15, %8
%33 = phi i32 [ 1, %8 ], [ 1, %21 ], [ %27, %29 ], [ 0, %24 ], [ 1, %15 ]
%34 = call i32 @BIO_free(i32* %6)
ret i32 %33
}