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


x86 assembly (clang, -O0):
<urlencode_put_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
cmp    -0x10(%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,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1060 <urlencode_put@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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