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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int verify_cert(uint8_t *x509_pem_certificates, uint32_t size) {
  printf("I received a buffer of %d bytes!\n", size);
  const char FILENAME[] = "/tmp/cert";
  FILE *outfile = fopen(FILENAME, "wb");
  if (outfile != NULL) {
    fwrite(x509_pem_certificates, 1, size, outfile);
    fclose(outfile);
    printf("Written to %s\n", FILENAME);
  }
  return 1;
}


x86 assembly (clang, -O0):
<verify_cert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0xebb(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xeb8(%rip),%ax
mov    %ax,-0xe(%rbp)
lea    -0x16(%rbp),%rdi
lea    0xeab(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c5 <verify_cert+0x85>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x16(%rbp),%rsi
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify_cert>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x7265632f706d742f,%rax
63 65 72
mov    %rax,(%rsp)
movw   $0x74,0x8(%rsp)
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b2 <verify_cert+0x72>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe87(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"I received a buffer of %d bytes!\0A\00"
@__const.verify_cert.FILENAME = [10 x i8] c"/tmp/cert\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [15 x i8] c"Written to %s\0A\00"
define i32 @verify_cert(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [10 x i8]
%6 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = bitcast [10 x i8]* %5 to i8*
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32*, i32** %3
%16 = load i32, i32* %4
%17 = load i32*, i32** %6
%18 = call i32 @fwrite(i32* %15, i32 1, i32 %16, i32* %17)
%19 = load i32*, i32** %6
%20 = call i32 @fclose(i32* %19)
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %14, %2
ret i32 1
}

LLVM IR (-O2):
@.str = [34 x i8] c"I received a buffer of %d bytes!\0A\00"
@__const.verify_cert.FILENAME = [10 x i8] c"/tmp/cert\00"
@.str.1 = [3 x i8] c"wb\00"
@.str.2 = [15 x i8] c"Written to %s\0A\00"
define i32 @verify_cert(i32* nocapture %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = tail call i32 @fwrite(i32* %0, i32 1, i32 %1, i32* %6)
%10 = tail call i32 @fclose(i32* %6)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %12
12: ; preds = %8, %2
ret i32 1
}