#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;

/* Variables and functions */
int EIO;
int ENOMEM;
size_t EVP_DecodeBlock(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(unsigned char *);
int fwrite(unsigned char *, size_t, int, int /*<<< orphan*/ *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
size_t strlen(char const *);
int /*<<< orphan*/ warnx(char *, ...);
int store_passphrase_from_base64(const char *b64_string, const char *filename,
                                 bool verbose) {
  size_t len, outlen, rawlen, i;
  unsigned char *buf;
  FILE *fp = NULL;
  int rc = 0;
  len = strlen(b64_string);
  rawlen = outlen = (len / 4) * 3;
  for (i = len - 1; b64_string[i] == '='; i--, rawlen--)
    ;
  buf = malloc(outlen);
  if (buf == NULL) {
    do {
      if (verbose)
        warnx("Malloc failed");
    } while (0);
    return -ENOMEM;
  }
  fp = fopen(filename, "w");
  if (fp == NULL) {
    do {
      if (verbose)
        warnx("Open of file '%s' failed: %s", filename, strerror(errno));
    } while (0);
    rc = -EIO;
    goto out;
  }
  len = EVP_DecodeBlock(buf, (unsigned char *)b64_string, len);
  if (len != outlen) {
    do {
      if (verbose)
        warnx("EVP_DecodeBlock failed");
    } while (0);
    goto out;
  }
  if (fwrite(buf, rawlen, 1, fp) != 1) {
    do {
      if (verbose)
        warnx("Writing file '%s' failed: %s", filename, strerror(errno));
    } while (0);
    goto out;
  }
out:
  if (fp != NULL)
    fclose(fp);
  free(buf);
  return rc;
}


x86 assembly (clang, -O0):
<store_passphrase_from_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
shr    $0x2,%rax
imul   $0x3,%rax,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3d,%eax
jne    1216 <store_passphrase_from_base64+0x86>
jmp    11f9 <store_passphrase_from_base64+0x69>
mov    -0x40(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x38(%rbp)
jmp    11df <store_passphrase_from_base64+0x4f>
mov    -0x30(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1263 <store_passphrase_from_base64+0xd3>
jmp    1233 <store_passphrase_from_base64+0xa3>
cmpl   $0x0,-0x1c(%rbp)
je     124b <store_passphrase_from_base64+0xbb>
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    1250 <store_passphrase_from_base64+0xc0>
xor    %eax,%eax
mov    0x2d7f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    13a7 <store_passphrase_from_base64+0x217>
mov    -0x18(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12d3 <store_passphrase_from_base64+0x143>
jmp    1287 <store_passphrase_from_base64+0xf7>
cmpl   $0x0,-0x1c(%rbp)
je     12bb <store_passphrase_from_base64+0x12b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x60(%rbp),%rsi
mov    %eax,%edx
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    12c0 <store_passphrase_from_base64+0x130>
xor    %eax,%eax
mov    0x2d17(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x54(%rbp)
jmp    1384 <store_passphrase_from_base64+0x1f4>
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <EVP_DecodeBlock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
je     131d <store_passphrase_from_base64+0x18d>
jmp    12fb <store_passphrase_from_base64+0x16b>
cmpl   $0x0,-0x1c(%rbp)
je     1313 <store_passphrase_from_base64+0x183>
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    1318 <store_passphrase_from_base64+0x188>
jmp    1384 <store_passphrase_from_base64+0x1f4>
mov    -0x48(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x50(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
cmp    $0x1,%eax
je     137f <store_passphrase_from_base64+0x1ef>
jmp    1341 <store_passphrase_from_base64+0x1b1>
cmpl   $0x0,-0x1c(%rbp)
je     1375 <store_passphrase_from_base64+0x1e5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
jmp    137a <store_passphrase_from_base64+0x1ea>
jmp    1384 <store_passphrase_from_base64+0x1f4>
jmp    1384 <store_passphrase_from_base64+0x1f4>
cmpq   $0x0,-0x50(%rbp)
je     1398 <store_passphrase_from_base64+0x208>
mov    -0x50(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_passphrase_from_base64>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r12d
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
call   1060 <strlen@plt>
mov    %rax,%r14
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
mov    %r14,%rcx
shr    $0x2,%rcx
lea    (%rcx,%rcx,2),%r15
lea    (%rcx,%rcx,2),%rbp
add    $0x1,%rbp
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbp
cmpb   $0x3d,(%rax)
lea    -0x1(%rax),%rax
je     11d0 <store_passphrase_from_base64+0x40>
mov    %r15,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     1276 <store_passphrase_from_base64+0xe6>
mov    %rax,%r13
mov    %r12d,0xc(%rsp)
lea    0xe11(%rip),%rsi
mov    0x10(%rsp),%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1296 <store_passphrase_from_base64+0x106>
mov    %rax,%r12
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <EVP_DecodeBlock@plt>
cmp    %r15,%rax
jne    12cd <store_passphrase_from_base64+0x13d>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
cmpl   $0x0,0xc(%rsp)
je     12e2 <store_passphrase_from_base64+0x152>
cmp    $0x1,%eax
je     12e2 <store_passphrase_from_base64+0x152>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdde(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    12e2 <store_passphrase_from_base64+0x152>
test   %r12d,%r12d
je     1289 <store_passphrase_from_base64+0xf9>
lea    0xd7e(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
mov    0x2d48(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    12f4 <store_passphrase_from_base64+0x164>
cmpl   $0x0,0xc(%rsp)
je     12c0 <store_passphrase_from_base64+0x130>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd5e(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <warnx@plt>
mov    0x2d19(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
jmp    12ec <store_passphrase_from_base64+0x15c>
cmpl   $0x0,0xc(%rsp)
je     12e2 <store_passphrase_from_base64+0x152>
lea    0xd52(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %ebx,%ebx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Malloc failed\00"
@ENOMEM = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"Open of file '%s' failed: %s\00"
@errno = global i32 0
@EIO = global i32 0
@.str.3 = [23 x i8] c"EVP_DecodeBlock failed\00"
@.str.4 = [29 x i8] c"Writing file '%s' failed: %s\00"
define i32 @store_passphrase_from_base64(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* null, i32** %13
store i32 0, i32* %14
%15 = load i8*, i8** %5
%16 = call i64 @strlen(i8* %15)
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = udiv i64 %17, 4
%19 = mul i64 %18, 3
store i64 %19, i64* %9
store i64 %19, i64* %10
%20 = load i64, i64* %8
%21 = sub i64 %20, 1
store i64 %21, i64* %11
br label %22
22: ; preds = %30, %3
%23 = load i8*, i8** %5
%24 = load i64, i64* %11
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 61
br i1 %28, label %29, label %35
29: ; preds = %22
br label %30
30: ; preds = %29
%31 = load i64, i64* %11
%32 = add i64 %31, -1
store i64 %32, i64* %11
%33 = load i64, i64* %10
%34 = add i64 %33, -1
store i64 %34, i64* %10
br label %22
35: ; preds = %22
%36 = load i64, i64* %9
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %12
%38 = load i8*, i8** %12
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %50
40: ; preds = %35
br label %41
41: ; preds = %40
%42 = load i32, i32* %7
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
br label %47
47: ; preds = %46
%48 = load i32, i32* @ENOMEM
%49 = sub nsw i32 0, %48
store i32 %49, i32* %4
br label %112
50: ; preds = %35
%51 = load i8*, i8** %6
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %52, i32** %13
%53 = load i32*, i32** %13
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %68
55: ; preds = %50
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %64
59: ; preds = %56
%60 = load i8*, i8** %6
%61 = load i32, i32* @errno
%62 = call i32 @strerror(i32 %61)
%63 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %60, i32 %62)
br label %64
64: ; preds = %59, %56
br label %65
65: ; preds = %64
%66 = load i32, i32* @EIO
%67 = sub nsw i32 0, %66
store i32 %67, i32* %14
br label %102
68: ; preds = %50
%69 = load i8*, i8** %12
%70 = load i8*, i8** %5
%71 = load i64, i64* %8
%72 = call i64 @EVP_DecodeBlock(i8* %69, i8* %70, i64 %71)
store i64 %72, i64* %8
%73 = load i64, i64* %8
%74 = load i64, i64* %9
%75 = icmp ne i64 %73, %74
br i1 %75, label %76, label %84
76: ; preds = %68
br label %77
77: ; preds = %76
%78 = load i32, i32* %7
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %82
82: ; preds = %80, %77
br label %83
83: ; preds = %82
br label %102
84: ; preds = %68
%85 = load i8*, i8** %12
%86 = load i64, i64* %10
%87 = load i32*, i32** %13
%88 = call i32 @fwrite(i8* %85, i64 %86, i32 1, i32* %87)
%89 = icmp ne i32 %88, 1
br i1 %89, label %90, label %101
90: ; preds = %84
br label %91
91: ; preds = %90
%92 = load i32, i32* %7
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %99
94: ; preds = %91
%95 = load i8*, i8** %6
%96 = load i32, i32* @errno
%97 = call i32 @strerror(i32 %96)
%98 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %95, i32 %97)
br label %99
99: ; preds = %94, %91
br label %100
100: ; preds = %99
br label %102
101: ; preds = %84
br label %102
102: ; preds = %101, %100, %83, %65
%103 = load i32*, i32** %13
%104 = icmp ne i32* %103, null
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = load i32*, i32** %13
%107 = call i32 @fclose(i32* %106)
br label %108
108: ; preds = %105, %102
%109 = load i8*, i8** %12
%110 = call i32 @free(i8* %109)
%111 = load i32, i32* %14
store i32 %111, i32* %4
br label %112
112: ; preds = %108, %47
%113 = load i32, i32* %4
ret i32 %113
}

LLVM IR (-O2):
@.str = [14 x i8] c"Malloc failed\00"
@ENOMEM = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"Open of file '%s' failed: %s\00"
@errno = global i32 0
@EIO = global i32 0
@.str.3 = [23 x i8] c"EVP_DecodeBlock failed\00"
@.str.4 = [29 x i8] c"Writing file '%s' failed: %s\00"
define i32 @store_passphrase_from_base64(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = lshr i64 %4, 2
%6 = mul nuw i64 %5, 3
br label %7
7: ; preds = %7, %3
%8 = phi i64 [ %6, %3 ], [ %14, %7 ]
%9 = phi i64 [ %4, %3 ], [ %10, %7 ]
%10 = add i64 %9, -1
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 61
%14 = add i64 %8, -1
br i1 %13, label %7, label %15
15: ; preds = %7
%16 = tail call i8* @malloc(i64 %6)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = icmp eq i32 %2, 0
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = load i32, i32* @ENOMEM
%24 = sub nsw i32 0, %23
br label %58
25: ; preds = %15
%26 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = icmp eq i32 %2, 0
br i1 %29, label %50, label %30
30: ; preds = %28
%31 = load i32, i32* @errno
%32 = tail call i32 @strerror(i32 %31)
%33 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %1, i32 %32)
br label %50
34: ; preds = %25
%35 = tail call i64 @EVP_DecodeBlock(i8* %16, i8* %0, i64 %4)
%36 = icmp eq i64 %35, %6
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = icmp eq i32 %2, 0
br i1 %38, label %53, label %39
39: ; preds = %37
%40 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %53
41: ; preds = %34
%42 = tail call i32 @fwrite(i8* %16, i64 %8, i32 1, i32* %26)
%43 = icmp ne i32 %42, 1
%44 = icmp ne i32 %2, 0
%45 = and i1 %44, %43
br i1 %45, label %46, label %53
46: ; preds = %41
%47 = load i32, i32* @errno
%48 = tail call i32 @strerror(i32 %47)
%49 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %1, i32 %48)
br label %53
50: ; preds = %28, %30
%51 = load i32, i32* @EIO
%52 = sub nsw i32 0, %51
br label %55
53: ; preds = %41, %46, %37, %39
%54 = tail call i32 @fclose(i32* %26)
br label %55
55: ; preds = %50, %53
%56 = phi i32 [ 0, %53 ], [ %52, %50 ]
%57 = tail call i32 @free(i8* %16)
br label %58
58: ; preds = %55, %22
%59 = phi i32 [ %24, %22 ], [ %56, %55 ]
ret i32 %59
}