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

/* Variables and functions */
int /*<<< orphan*/ *PEM_read_X509(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int read_public_key(void **pub_key_ptr, char *name) {
  X509 *x509;
  FILE *file;
  if ((file = fopen(name, "r")) == NULL ||
      (x509 = PEM_read_X509(file, NULL, NULL, NULL)) == NULL) {
    printf("Failed to read the public key\n");
    fclose(file);
    return 0;
  }
  fclose(file);
  *pub_key_ptr = x509;
  return 1;
}


x86 assembly (clang, -O0):
<read_public_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     118f <read_public_key+0x4f>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <PEM_read_X509@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b0 <read_public_key+0x70>
lea    0xe6c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cb <read_public_key+0x8b>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_public_key>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%r14
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118a <read_public_key+0x4a>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <PEM_read_X509@plt>
test   %rax,%rax
je     118a <read_public_key+0x4a>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,(%r14)
mov    $0x1,%eax
jmp    11a0 <read_public_key+0x60>
lea    0xe71(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [31 x i8] c"Failed to read the public key\0A\00"
define i32 @read_public_key(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8** %0, i8*** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = load i32*, i32** %7
%13 = call i32* @PEM_read_X509(i32* %12, i32* null, i32* null, i32* null)
store i32* %13, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %11, %2
%16 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32*, i32** %7
%18 = call i32 @fclose(i32* %17)
store i32 0, i32* %3
br label %25
19: ; preds = %11
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
%22 = load i32*, i32** %6
%23 = bitcast i32* %22 to i8*
%24 = load i8**, i8*** %4
store i8* %23, i8** %24
store i32 1, i32* %3
br label %25
25: ; preds = %19, %15
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@str = [30 x i8] c"Failed to read the public key\00"
define i32 @read_public_key(i8** nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32* @PEM_read_X509(i32* %3, i32* null, i32* null, i32* null)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @fclose(i32* %3)
br label %14
11: ; preds = %5
%12 = tail call i32 @fclose(i32* %3)
%13 = bitcast i8** %0 to i32**
store i32* %6, i32** %13
br label %14
14: ; preds = %11, %8
%15 = phi i32 [ 0, %8 ], [ 1, %11 ]
ret i32 %15
}