#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*/ assert(int);
char *malloc(unsigned long);
int mbstowcs(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned long);
int /*<<< orphan*/ urlencode_put(char *, unsigned long, char const *, size_t);
char *urlencode(const char *mb_input) {
  assert(NULL != mb_input);
  size_t input_len = mbstowcs(NULL, mb_input, 0) + 1;
  unsigned long int output_allocation = sizeof(char) * (input_len * 12);
  char *output = malloc(output_allocation);
  memset(output, 0, output_allocation);
  urlencode_put(output, output_allocation, mb_input, input_len);
  return output;
}


x86 assembly (clang, -O0):
<urlencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
xor    %edx,%edx
call   1030 <mbstowcs@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x10(%rbp)
imul   $0xc,-0x10(%rbp),%rax
shl    $0x0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1070 <urlencode_put@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urlencode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1030 <mbstowcs@plt>
movslq %eax,%rbx
lea    0x4(,%rbx,4),%rax
add    $0x1,%rbx
lea    (%rax,%rax,2),%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <urlencode_put@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @urlencode(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = icmp ne i8* null, %6
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %2
%11 = call i32 @mbstowcs(i32* null, i8* %10, i32 0)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %3
%14 = load i64, i64* %3
%15 = mul i64 %14, 12
%16 = mul i64 1, %15
store i64 %16, i64* %4
%17 = load i64, i64* %4
%18 = call i8* @malloc(i64 %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = load i64, i64* %4
%21 = call i32 @memset(i8* %19, i32 0, i64 %20)
%22 = load i8*, i8** %5
%23 = load i64, i64* %4
%24 = load i8*, i8** %2
%25 = load i64, i64* %3
%26 = call i32 @urlencode_put(i8* %22, i64 %23, i8* %24, i64 %25)
%27 = load i8*, i8** %5
ret i8* %27
}

LLVM IR (-O2):
define i8* @urlencode(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @mbstowcs(i32* null, i8* %0, i32 0)
%6 = add nsw i32 %5, 1
%7 = sext i32 %6 to i64
%8 = mul nsw i64 %7, 12
%9 = tail call i8* @malloc(i64 %8)
%10 = tail call i32 @memset(i8* %9, i32 0, i64 %8)
%11 = tail call i32 @urlencode_put(i8* %9, i64 %8, i8* %0, i64 %7)
ret i8* %9
}