#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 */

/* Variables and functions */
scalar_t__ base64_decode(unsigned char *, int *, unsigned char *,
                         int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strlen(char *);
char *pdkim_decode_base64(char *str, int *num_decoded) {
  int dlen = 0;
  char *res;
  base64_decode(NULL, &dlen, (unsigned char *)str, strlen(str));
  res = malloc(dlen + 1);
  if (res == NULL)
    return NULL;
  if (base64_decode((unsigned char *)res, &dlen, (unsigned char *)str,
                    strlen(str)) != 0) {
    free(res);
    return NULL;
  }
  if (num_decoded != NULL)
    *num_decoded = dlen;
  return res;
}


x86 assembly (clang, -O0):
<pdkim_decode_base64>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x1c(%rbp),%rsi
call   1060 <base64_decode@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a2 <pdkim_decode_base64+0x62>
movq   $0x0,-0x8(%rbp)
jmp    120a <pdkim_decode_base64+0xca>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    %eax,%ecx
lea    -0x1c(%rbp),%rsi
call   1060 <base64_decode@plt>
cmp    $0x0,%rax
je     11ee <pdkim_decode_base64+0xae>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    120a <pdkim_decode_base64+0xca>
cmpq   $0x0,-0x18(%rbp)
je     1202 <pdkim_decode_base64+0xc2>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdkim_decode_base64>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
call   1040 <strlen@plt>
xor    %r12d,%r12d
lea    0x4(%rsp),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <base64_decode@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11be <pdkim_decode_base64+0x7e>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x4(%rsp),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1060 <base64_decode@plt>
test   %rax,%rax
je     11af <pdkim_decode_base64+0x6f>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
jmp    11be <pdkim_decode_base64+0x7e>
test   %r14,%r14
je     11bb <pdkim_decode_base64+0x7b>
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
mov    %r15,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @pdkim_decode_base64(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
%11 = call i64 @base64_decode(i8* null, i32* %6, i8* %8, i32 %10)
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i8* null, i8** %3
br label %36
18: ; preds = %2
%19 = load i8*, i8** %7
%20 = load i8*, i8** %4
%21 = load i8*, i8** %4
%22 = call i32 @strlen(i8* %21)
%23 = call i64 @base64_decode(i8* %19, i32* %6, i8* %20, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
store i8* null, i8** %3
br label %36
28: ; preds = %18
%29 = load i32*, i32** %5
%30 = icmp ne i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* %6
%33 = load i32*, i32** %5
store i32 %32, i32* %33
br label %34
34: ; preds = %31, %28
%35 = load i8*, i8** %7
store i8* %35, i8** %3
br label %36
36: ; preds = %34, %25, %17
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
define i8* @pdkim_decode_base64(i8* %0, i32* writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = tail call i32 @strlen(i8* %0)
%6 = call i64 @base64_decode(i8* null, i32* %3, i8* %0, i32 %5)
%7 = load i32, i32* %3
%8 = add nsw i32 %7, 1
%9 = call i8* @malloc(i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %21, label %11
11: ; preds = %2
%12 = call i32 @strlen(i8* %0)
%13 = call i64 @base64_decode(i8* %9, i32* %3, i8* %0, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @free(i8* %9)
br label %21
17: ; preds = %11
%18 = icmp eq i32* %1, null
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = load i32, i32* %3
store i32 %20, i32* %1
br label %21
21: ; preds = %17, %19, %2, %15
%22 = phi i8* [ null, %15 ], [ null, %2 ], [ %9, %19 ], [ %9, %17 ]
ret i8* %22
}