#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 PICA_id_from_X509(int /*<<< orphan*/ *, unsigned char *);
int /*<<< orphan*/ X509_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ perror(char const *);
int PICA_get_id_from_cert_file(const char *cert_file, unsigned char *id) {
  X509 *x;
  FILE *f;
  int ret;
  f = fopen(cert_file, "r");
  if (!f) {
    perror(cert_file);
    return 0;
  }
  x = PEM_read_X509(f, 0, 0, 0);
  fclose(f);
  if (!x) {
    return 0;
  }
  ret = PICA_id_from_X509(x, id);
  X509_free(x);
  return ret;
}


x86 assembly (clang, -O0):
<PICA_get_id_from_cert_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a4 <PICA_get_id_from_cert_file+0x44>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <PICA_get_id_from_cert_file+0x96>
mov    -0x28(%rbp),%rdi
xor    %ecx,%ecx
mov    %ecx,%esi
mov    %ecx,%edx
call   1040 <PEM_read_X509@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
jne    11d7 <PICA_get_id_from_cert_file+0x77>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <PICA_get_id_from_cert_file+0x96>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <PICA_id_from_X509@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <X509_free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PICA_get_id_from_cert_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b6 <PICA_get_id_from_cert_file+0x56>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <PEM_read_X509@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   %r15,%r15
je     11be <PICA_get_id_from_cert_file+0x5e>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <PICA_id_from_X509@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <X509_free@plt>
mov    %ebx,%eax
jmp    11c0 <PICA_get_id_from_cert_file+0x60>
mov    %r15,%rdi
call   1080 <perror@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @PICA_get_id_from_cert_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @perror(i8* %14)
store i32 0, i32* %3
br label %31
16: ; preds = %2
%17 = load i32*, i32** %7
%18 = call i32* @PEM_read_X509(i32* %17, i32 0, i32 0, i32 0)
store i32* %18, i32** %6
%19 = load i32*, i32** %7
%20 = call i32 @fclose(i32* %19)
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %24, label %23
23: ; preds = %16
store i32 0, i32* %3
br label %31
24: ; preds = %16
%25 = load i32*, i32** %6
%26 = load i8*, i8** %5
%27 = call i32 @PICA_id_from_X509(i32* %25, i8* %26)
store i32 %27, i32* %8
%28 = load i32*, i32** %6
%29 = call i32 @X509_free(i32* %28)
%30 = load i32, i32* %8
store i32 %30, i32* %3
br label %31
31: ; preds = %24, %23, %13
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @PICA_get_id_from_cert_file(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* %0)
br label %14
7: ; preds = %2
%8 = tail call i32* @PEM_read_X509(i32* %3, i32 0, i32 0, i32 0)
%9 = tail call i32 @fclose(i32* %3)
%10 = icmp eq i32* %8, null
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = tail call i32 @PICA_id_from_X509(i32* %8, i8* %1)
%13 = tail call i32 @X509_free(i32* %8)
br label %14
14: ; preds = %7, %11, %5
%15 = phi i32 [ %12, %11 ], [ 0, %5 ], [ 0, %7 ]
ret i32 %15
}