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

/* Variables and functions */
int /*<<< orphan*/ EVP_PKEY_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ PEM_write_PUBKEY(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *ReadPrivKey_FromFile(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *stdout;
int main(int argc, char **argv) {
  EVP_PKEY *pkey = NULL;
  FILE *fppub;
  pkey = ReadPrivKey_FromFile("/home/root/privatekey.pem", NULL);
  fppub = fopen("/home/root/pubkey.pem", "w");
  PEM_write_PUBKEY(fppub, pkey);
  PEM_write_PUBKEY(stdout, pkey);
  EVP_PKEY_free(pkey);
  fclose(fppub);
  return 1;
err:
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <ReadPrivKey_FromFile@plt>
mov    %rax,-0x18(%rbp)
lea    0xe91(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <PEM_write_PUBKEY@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <PEM_write_PUBKEY@plt>
mov    -0x18(%rbp),%rdi
call   1040 <EVP_PKEY_free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
xor    %esi,%esi
call   1050 <ReadPrivKey_FromFile@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rdi
lea    0xebd(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1070 <PEM_write_PUBKEY@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%rdi
mov    %rbx,%rsi
call   1070 <PEM_write_PUBKEY@plt>
mov    %rbx,%rdi
call   1040 <EVP_PKEY_free@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/home/root/privatekey.pem\00"
@.str.1 = [22 x i8] c"/home/root/pubkey.pem\00"
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%8 = call i32* @ReadPrivKey_FromFile(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* null)
store i32* %8, i32** %6
%9 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = load i32*, i32** %6
%12 = call i32 @PEM_write_PUBKEY(i32* %10, i32* %11)
%13 = load i32*, i32** @stdout
%14 = load i32*, i32** %6
%15 = call i32 @PEM_write_PUBKEY(i32* %13, i32* %14)
%16 = load i32*, i32** %6
%17 = call i32 @EVP_PKEY_free(i32* %16)
%18 = load i32*, i32** %7
%19 = call i32 @fclose(i32* %18)
store i32 1, i32* %3
br label %21
20: ; No predecessors!
store i32 0, i32* %3
br label %21
21: ; preds = %20, %2
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str = [26 x i8] c"/home/root/privatekey.pem\00"
@.str.1 = [22 x i8] c"/home/root/pubkey.pem\00"
@.str.2 = [2 x i8] c"w\00"
@stdout = global i32* null
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @ReadPrivKey_FromFile(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32* null)
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @PEM_write_PUBKEY(i32* %4, i32* %3)
%6 = load i32*, i32** @stdout
%7 = tail call i32 @PEM_write_PUBKEY(i32* %6, i32* %3)
%8 = tail call i32 @EVP_PKEY_free(i32* %3)
%9 = tail call i32 @fclose(i32* %4)
ret i32 1
}