#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*/ u_char;
struct sshbuf {
  int dummy;
};

/* Variables and functions */
int b64_pton(char const *, int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(size_t);
int /*<<< orphan*/ memset_s(int /*<<< orphan*/ *, size_t, int, size_t);
int sshbuf_put(struct sshbuf *, int /*<<< orphan*/ *, int);
size_t strlen(char const *);
int sshbuf_b64tod(struct sshbuf *buf, const char *b64) {
  size_t plen = strlen(b64);
  int nlen, r;
  u_char *p;
  if (plen == 0)
    return 0;
  if ((p = malloc(plen)) == NULL)
    return -2;
  if ((nlen = b64_pton(b64, p, plen)) < 0) {
    memset_s(p, plen, 0x0, plen);
    free(p);
    return -4;
  }
  if ((r = sshbuf_put(buf, p, nlen)) < 0) {
    memset_s(p, plen, 0x0, plen);
    free(p);
    return r;
  }
  memset_s(p, plen, 0x0, plen);
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<sshbuf_b64tod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <sshbuf_b64tod+0x34>
movl   $0x0,-0x4(%rbp)
jmp    1262 <sshbuf_b64tod+0x102>
mov    -0x20(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11b7 <sshbuf_b64tod+0x57>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1262 <sshbuf_b64tod+0x102>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <b64_pton@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11fc <sshbuf_b64tod+0x9c>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1080 <memset_s@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1262 <sshbuf_b64tod+0x102>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <sshbuf_put@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jge    123f <sshbuf_b64tod+0xdf>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1080 <memset_s@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1262 <sshbuf_b64tod+0x102>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1080 <memset_s@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sshbuf_b64tod>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     11d0 <sshbuf_b64tod+0x70>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d4 <sshbuf_b64tod+0x74>
mov    %rax,%r14
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <b64_pton@plt>
test   %eax,%eax
js     11db <sshbuf_b64tod+0x7b>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <sshbuf_put@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %rbx,%rcx
call   1080 <memset_s@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
sar    $0x1f,%eax
and    %ebp,%eax
jmp    11f8 <sshbuf_b64tod+0x98>
xor    %eax,%eax
jmp    11f8 <sshbuf_b64tod+0x98>
mov    $0xfffffffe,%eax
jmp    11f8 <sshbuf_b64tod+0x98>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %rbx,%rcx
call   1080 <memset_s@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0xfffffffc,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_b64tod(%struct.sshbuf* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sshbuf*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store %struct.sshbuf* %0, %struct.sshbuf** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %54
15: ; preds = %2
%16 = load i64, i64* %6
%17 = call i32* @malloc(i64 %16)
store i32* %17, i32** %9
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -2, i32* %3
br label %54
20: ; preds = %15
%21 = load i8*, i8** %5
%22 = load i32*, i32** %9
%23 = load i64, i64* %6
%24 = call i32 @b64_pton(i8* %21, i32* %22, i64 %23)
store i32 %24, i32* %7
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %20
%27 = load i32*, i32** %9
%28 = load i64, i64* %6
%29 = load i64, i64* %6
%30 = call i32 @memset_s(i32* %27, i64 %28, i32 0, i64 %29)
%31 = load i32*, i32** %9
%32 = call i32 @free(i32* %31)
store i32 -4, i32* %3
br label %54
33: ; preds = %20
%34 = load %struct.sshbuf*, %struct.sshbuf** %4
%35 = load i32*, i32** %9
%36 = load i32, i32* %7
%37 = call i32 @sshbuf_put(%struct.sshbuf* %34, i32* %35, i32 %36)
store i32 %37, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %33
%40 = load i32*, i32** %9
%41 = load i64, i64* %6
%42 = load i64, i64* %6
%43 = call i32 @memset_s(i32* %40, i64 %41, i32 0, i64 %42)
%44 = load i32*, i32** %9
%45 = call i32 @free(i32* %44)
%46 = load i32, i32* %8
store i32 %46, i32* %3
br label %54
47: ; preds = %33
%48 = load i32*, i32** %9
%49 = load i64, i64* %6
%50 = load i64, i64* %6
%51 = call i32 @memset_s(i32* %48, i64 %49, i32 0, i64 %50)
%52 = load i32*, i32** %9
%53 = call i32 @free(i32* %52)
store i32 0, i32* %3
br label %54
54: ; preds = %47, %39, %26, %19, %14
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.sshbuf = type { i32 }
define i32 @sshbuf_b64tod(%struct.sshbuf* %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = tail call i32* @malloc(i64 %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %20, label %8
8: ; preds = %5
%9 = tail call i32 @b64_pton(i8* %1, i32* %6, i64 %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @memset_s(i32* %6, i64 %3, i32 0, i64 %3)
%13 = tail call i32 @free(i32* %6)
br label %20
14: ; preds = %8
%15 = tail call i32 @sshbuf_put(%struct.sshbuf* %0, i32* %6, i32 %9)
%16 = icmp slt i32 %15, 0
%17 = tail call i32 @memset_s(i32* %6, i64 %3, i32 0, i64 %3)
%18 = tail call i32 @free(i32* %6)
%19 = select i1 %16, i32 %15, i32 0
br label %20
20: ; preds = %14, %5, %2, %11
%21 = phi i32 [ -4, %11 ], [ 0, %2 ], [ -2, %5 ], [ %19, %14 ]
ret i32 %21
}