#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*/ PEM_write_PUBKEY(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *RSA_fromBase64(char const *, char const *);
int /*<<< orphan*/ assert_syntax(int, char **);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  assert_syntax(argc, argv);
  const char *modulus = argv[1];
  const char *exp = argv[2];
  const char *filename = argv[3];
  EVP_PKEY *pkey = RSA_fromBase64(modulus, exp);
  if (pkey == NULL) {
    fprintf(stderr, "an error occurred :(\n");
    return 2;
  } else {
    printf("success decoded into RSA public key\n");
    FILE *file = fopen(filename, "w");
    PEM_write_PUBKEY(file, pkey);
    fflush(file);
    fclose(file);
    printf("written to file: %s\n", filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <assert_syntax@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <RSA_fromBase64@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1203 <main+0x83>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    125d <main+0xdd>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10a0 <PEM_write_PUBKEY@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rsi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
call   1030 <assert_syntax@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x18(%rbx),%r14
call   1090 <RSA_fromBase64@plt>
test   %rax,%rax
je     1204 <main+0x74>
mov    %rax,%r15
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   10b0 <PEM_write_PUBKEY@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe22(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    121e <main+0x8e>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"an error occurred :(\0A\00"
@.str.1 = [37 x i8] c"success decoded into RSA public key\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [21 x i8] c"written to file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @assert_syntax(i32 %11, i8** %12)
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32* @RSA_fromBase64(i8* %23, i8* %24)
store i32* %25, i32** %9
%26 = load i32*, i32** %9
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %3
br label %45
31: ; preds = %2
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%33 = load i8*, i8** %8
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %10
%35 = load i32*, i32** %10
%36 = load i32*, i32** %9
%37 = call i32 @PEM_write_PUBKEY(i32* %35, i32* %36)
%38 = load i32*, i32** %10
%39 = call i32 @fflush(i32* %38)
%40 = load i32*, i32** %10
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %8
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %31
store i32 0, i32* %3
br label %45
45: ; preds = %44, %28
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"an error occurred :(\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [21 x i8] c"written to file: %s\0A\00"
@str = [36 x i8] c"success decoded into RSA public key\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @assert_syntax(i32 %0, i8** %1)
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8*, i8** %1, i64 3
%9 = load i8*, i8** %8
%10 = tail call i32* @RSA_fromBase64(i8* %5, i8* %7)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %22
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%17 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @PEM_write_PUBKEY(i32* %17, i32* %10)
%19 = tail call i32 @fflush(i32* %17)
%20 = tail call i32 @fclose(i32* %17)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %9)
br label %22
22: ; preds = %15, %12
%23 = phi i32 [ 2, %12 ], [ 0, %15 ]
ret i32 %23
}