#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*/ bzero(int /*<<< orphan*/ *, size_t);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *malloc(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) {
    bzero(p, plen);
    free(p);
    return -4;
  }
  if ((r = sshbuf_put(buf, p, nlen)) < 0) {
    bzero(p, plen);
    free(p);
    return r;
  }
  bzero(p, 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    1250 <sshbuf_b64tod+0xf0>
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    1250 <sshbuf_b64tod+0xf0>
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    11f6 <sshbuf_b64tod+0x96>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <bzero@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0xfffffffc,-0x4(%rbp)
jmp    1250 <sshbuf_b64tod+0xf0>
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    1233 <sshbuf_b64tod+0xd3>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <bzero@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1250 <sshbuf_b64tod+0xf0>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <bzero@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     11cb <sshbuf_b64tod+0x6b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     11cf <sshbuf_b64tod+0x6f>
mov    %rax,%r14
mov    %r12,%rdi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1060 <b64_pton@plt>
test   %eax,%eax
js     11d6 <sshbuf_b64tod+0x76>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <sshbuf_put@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <bzero@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
sar    $0x1f,%eax
and    %ebp,%eax
jmp    11ee <sshbuf_b64tod+0x8e>
xor    %eax,%eax
jmp    11ee <sshbuf_b64tod+0x8e>
mov    $0xfffffffe,%eax
jmp    11ee <sshbuf_b64tod+0x8e>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <bzero@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 %51
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 %51
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 %32
26: ; preds = %20
%27 = load i32*, i32** %9
%28 = load i64, i64* %6
%29 = call i32 @bzero(i32* %27, i64 %28)
%30 = load i32*, i32** %9
%31 = call i32 @free(i32* %30)
store i32 -4, i32* %3
br label %51
32: ; preds = %20
%33 = load %struct.sshbuf*, %struct.sshbuf** %4
%34 = load i32*, i32** %9
%35 = load i32, i32* %7
%36 = call i32 @sshbuf_put(%struct.sshbuf* %33, i32* %34, i32 %35)
store i32 %36, i32* %8
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i32*, i32** %9
%40 = load i64, i64* %6
%41 = call i32 @bzero(i32* %39, i64 %40)
%42 = load i32*, i32** %9
%43 = call i32 @free(i32* %42)
%44 = load i32, i32* %8
store i32 %44, i32* %3
br label %51
45: ; preds = %32
%46 = load i32*, i32** %9
%47 = load i64, i64* %6
%48 = call i32 @bzero(i32* %46, i64 %47)
%49 = load i32*, i32** %9
%50 = call i32 @free(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %45, %38, %26, %19, %14
%52 = load i32, i32* %3
ret i32 %52
}

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 @bzero(i32* %6, 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 @bzero(i32* %6, 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
}