#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 */
int /*<<< orphan*/ base64buf(char *, char const *, size_t);
size_t base64len(size_t);
char *malloc(size_t);
char *base64buf_url(const char *data, size_t len) {
  size_t i, sz;
  char *buf;
  sz = base64len(len);
  if (NULL == (buf = malloc(sz)))
    return (NULL);
  base64buf(buf, data, len);
  for (i = 0; i < sz; i++)
    if ('+' == buf[i])
      buf[i] = '-';
    else if ('/' == buf[i])
      buf[i] = '_';
    else if ('=' == buf[i])
      buf[i] = '\0';
  return (buf);
}


x86 assembly (clang, -O0):
<base64buf_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <base64len@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x30(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1175 <base64buf_url+0x45>
movq   $0x0,-0x8(%rbp)
jmp    123d <base64buf_url+0x10d>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <base64buf@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1235 <base64buf_url+0x105>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2b,%eax
cmp    %ecx,%eax
jne    11c6 <base64buf_url+0x96>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    121f <base64buf_url+0xef>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x2f,%eax
cmp    %ecx,%eax
jne    11f0 <base64buf_url+0xc0>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    121a <base64buf_url+0xea>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x3d,%eax
cmp    %ecx,%eax
jne    1215 <base64buf_url+0xe5>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    121a <base64buf_url+0xea>
jmp    121f <base64buf_url+0xef>
jmp    1224 <base64buf_url+0xf4>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118e <base64buf_url+0x5e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<base64buf_url>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1030 <base64len@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     122d <base64buf_url+0xfd>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <base64buf@plt>
test   %r14,%r14
je     122d <base64buf_url+0xfd>
cmp    $0x1,%r14
jne    11ab <base64buf_url+0x7b>
xor    %eax,%eax
test   $0x1,%r14b
je     122d <base64buf_url+0xfd>
mov    (%rbx,%rax,1),%cl
cmp    $0x2b,%cl
je     1224 <base64buf_url+0xf4>
cmp    $0x2f,%cl
je     1228 <base64buf_url+0xf8>
cmp    $0x3d,%cl
jne    122d <base64buf_url+0xfd>
xor    %ecx,%ecx
jmp    122a <base64buf_url+0xfa>
mov    %r14,%rcx
and    $0xfffffffffffffffe,%rcx
xor    %eax,%eax
jmp    11cf <base64buf_url+0x9f>
cs nopw 0x0(%rax,%rax,1)
mov    $0x5f,%dl
mov    %dl,0x1(%rbx,%rax,1)
add    $0x2,%rax
cmp    %rax,%rcx
je     117c <base64buf_url+0x4c>
movzbl (%rbx,%rax,1),%edx
cmp    $0x2b,%dl
je     11f0 <base64buf_url+0xc0>
cmp    $0x3d,%dl
je     1200 <base64buf_url+0xd0>
cmp    $0x2f,%dl
jne    1205 <base64buf_url+0xd5>
mov    $0x5f,%dl
jmp    1202 <base64buf_url+0xd2>
cs nopw 0x0(%rax,%rax,1)
mov    $0x2d,%dl
jmp    1202 <base64buf_url+0xd2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
mov    %dl,(%rbx,%rax,1)
movzbl 0x1(%rbx,%rax,1),%edx
cmp    $0x2b,%dl
je     1220 <base64buf_url+0xf0>
cmp    $0x2f,%dl
je     11c0 <base64buf_url+0x90>
cmp    $0x3d,%dl
jne    11c6 <base64buf_url+0x96>
xor    %edx,%edx
jmp    11c2 <base64buf_url+0x92>
nopl   (%rax)
mov    $0x2d,%dl
jmp    11c2 <base64buf_url+0x92>
mov    $0x2d,%cl
jmp    122a <base64buf_url+0xfa>
mov    $0x5f,%cl
mov    %cl,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @base64buf_url(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i64, i64* %5
%10 = call i64 @base64len(i64 %9)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %8
%13 = icmp eq i8* null, %12
br i1 %13, label %14, label %15
14: ; preds = %2
store i8* null, i8** %3
br label %65
15: ; preds = %2
%16 = load i8*, i8** %8
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = call i32 @base64buf(i8* %16, i8* %17, i64 %18)
store i64 0, i64* %6
br label %20
20: ; preds = %60, %15
%21 = load i64, i64* %6
%22 = load i64, i64* %7
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %63
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 43, %29
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = load i8*, i8** %8
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8 45, i8* %34
br label %59
35: ; preds = %24
%36 = load i8*, i8** %8
%37 = load i64, i64* %6
%38 = getelementptr inbounds i8, i8* %36, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 47, %40
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i8*, i8** %8
%44 = load i64, i64* %6
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8 95, i8* %45
br label %58
46: ; preds = %35
%47 = load i8*, i8** %8
%48 = load i64, i64* %6
%49 = getelementptr inbounds i8, i8* %47, i64 %48
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 61, %51
br i1 %52, label %53, label %57
53: ; preds = %46
%54 = load i8*, i8** %8
%55 = load i64, i64* %6
%56 = getelementptr inbounds i8, i8* %54, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %53, %46
br label %58
58: ; preds = %57, %42
br label %59
59: ; preds = %58, %31
br label %60
60: ; preds = %59
%61 = load i64, i64* %6
%62 = add i64 %61, 1
store i64 %62, i64* %6
br label %20
63: ; preds = %20
%64 = load i8*, i8** %8
store i8* %64, i8** %3
br label %65
65: ; preds = %63, %14
%66 = load i8*, i8** %3
ret i8* %66
}

LLVM IR (-O2):
define i8* @base64buf_url(i8* %0, i64 %1) {
%3 = tail call i64 @base64len(i64 %1)
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %45, label %6
6: ; preds = %2
%7 = tail call i32 @base64buf(i8* %4, i8* %0, i64 %1)
%8 = icmp eq i64 %3, 0
br i1 %8, label %45, label %9
9: ; preds = %6
%10 = and i64 %3, 1
%11 = icmp eq i64 %3, 1
br i1 %11, label %35, label %12
12: ; preds = %9
%13 = and i64 %3, -2
br label %14
14: ; preds = %31, %12
%15 = phi i64 [ 0, %12 ], [ %32, %31 ]
%16 = phi i64 [ 0, %12 ], [ %33, %31 ]
%17 = getelementptr inbounds i8, i8* %4, i64 %15
%18 = load i8, i8* %17
switch i8 %18, label %23 [
i8 43, label %21
i8 47, label %19
i8 61, label %20
]
19: ; preds = %14
br label %21
20: ; preds = %14
br label %21
21: ; preds = %14, %19, %20
%22 = phi i8 [ 0, %20 ], [ 95, %19 ], [ 45, %14 ]
store i8 %22, i8* %17
br label %23
23: ; preds = %21, %14
%24 = or i64 %15, 1
%25 = getelementptr inbounds i8, i8* %4, i64 %24
%26 = load i8, i8* %25
switch i8 %26, label %31 [
i8 43, label %29
i8 47, label %28
i8 61, label %27
]
27: ; preds = %23
br label %29
28: ; preds = %23
br label %29
29: ; preds = %28, %27, %23
%30 = phi i8 [ 0, %27 ], [ 95, %28 ], [ 45, %23 ]
store i8 %30, i8* %25
br label %31
31: ; preds = %29, %23
%32 = add nuw i64 %15, 2
%33 = add i64 %16, 2
%34 = icmp eq i64 %33, %13
br i1 %34, label %35, label %14
35: ; preds = %31, %9
%36 = phi i64 [ 0, %9 ], [ %32, %31 ]
%37 = icmp eq i64 %10, 0
br i1 %37, label %45, label %38
38: ; preds = %35
%39 = getelementptr inbounds i8, i8* %4, i64 %36
%40 = load i8, i8* %39
switch i8 %40, label %45 [
i8 43, label %43
i8 47, label %42
i8 61, label %41
]
41: ; preds = %38
br label %43
42: ; preds = %38
br label %43
43: ; preds = %42, %41, %38
%44 = phi i8 [ 0, %41 ], [ 95, %42 ], [ 45, %38 ]
store i8 %44, i8* %39
br label %45
45: ; preds = %35, %43, %38, %6, %2
ret i8* %4
}