#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 */
struct x509 {
  int dummy;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ slurp(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ x509_addpem(struct x509 *, char *, char *);
void readcert(struct x509 *cert, char *certfile) {
  char buf[32768];
  slurp(certfile, buf, sizeof(buf));
  if (!x509_addpem(cert, buf, "CERTIFICATE")) {
    fprintf(stderr, "%s: not a certificate\n", certfile);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<readcert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8010,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8010(%rbp),%rsi
mov    $0x8000,%edx
call   1030 <slurp@plt>
mov    -0x8(%rbp),%rdi
lea    -0x8010(%rbp),%rsi
lea    0xe86(%rip),%rdx
call   1050 <x509_addpem@plt>
cmp    $0x0,%eax
jne    11ab <readcert+0x6b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x8010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readcert>:
push   %r15
push   %r14
push   %rbx
sub    $0x8000,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%r15
mov    %rsi,%rdi
mov    %r15,%rsi
mov    $0x8000,%edx
call   1030 <slurp@plt>
lea    0xe94(%rip),%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <x509_addpem@plt>
test   %eax,%eax
je     1188 <readcert+0x48>
add    $0x8000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.x509 = type { i32 }
@.str = [12 x i8] c"CERTIFICATE\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"%s: not a certificate\0A\00"
define void @readcert(%struct.x509* %0, i8* %1) {
%3 = alloca %struct.x509*
%4 = alloca i8*
%5 = alloca [32768 x i8]
store %struct.x509* %0, %struct.x509** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%8 = call i32 @slurp(i8* %6, i8* %7, i32 32768)
%9 = load %struct.x509*, %struct.x509** %3
%10 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%11 = call i32 @x509_addpem(%struct.x509* %9, i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
ret void
}

LLVM IR (-O2):
%struct.x509 = type { i32 }
@.str = [12 x i8] c"CERTIFICATE\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"%s: not a certificate\0A\00"
define void @readcert(%struct.x509* %0, i8* %1) {
%3 = alloca [32768 x i8]
%4 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%5 = call i32 @slurp(i8* %1, i8* %4, i32 32768)
%6 = call i32 @x509_addpem(%struct.x509* %0, i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
ret void
}