#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 add_percent_encoded_char(char, char **, char *);
int add_untransformed_char(char, char **, char *);
scalar_t__ is_url_encode_unreserved_char(char);
bool add_url_encoded_char(char ch, char **buffer, char *buffer_end) {
  if (is_url_encode_unreserved_char(ch)) {
    return add_untransformed_char(ch, buffer, buffer_end);
  } else if (ch == ' ') {
    return add_untransformed_char('+', buffer, buffer_end);
  } else {
    return add_percent_encoded_char(ch, buffer, buffer_end);
  }
}


x86 assembly (clang, -O0):
<add_url_encoded_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <is_url_encode_unreserved_char@plt>
cmp    $0x0,%rax
je     1174 <add_url_encoded_char+0x44>
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movsbl %al,%edi
call   1040 <add_untransformed_char@plt>
mov    %eax,-0x4(%rbp)
jmp    11b1 <add_url_encoded_char+0x81>
movsbl -0x5(%rbp),%eax
cmp    $0x20,%eax
jne    119b <add_url_encoded_char+0x6b>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x2b,%edi
call   1040 <add_untransformed_char@plt>
mov    %eax,-0x4(%rbp)
jmp    11b1 <add_url_encoded_char+0x81>
mov    -0x5(%rbp),%al
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movsbl %al,%edi
call   1050 <add_percent_encoded_char@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_url_encoded_char>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
call   1030 <is_url_encode_unreserved_char@plt>
test   %rax,%rax
je     114c <add_url_encoded_char+0x1c>
movsbl %bpl,%edi
jmp    1157 <add_url_encoded_char+0x27>
cmp    $0x20,%bpl
jne    1166 <add_url_encoded_char+0x36>
mov    $0x2b,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <add_untransformed_char@plt>
movsbl %bpl,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <add_percent_encoded_char@plt>

LLVM IR (-O0):
define i32 @add_url_encoded_char(i8 signext %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8**
%7 = alloca i8*
store i8 %0, i8* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%8 = load i8, i8* %5
%9 = call i64 @is_url_encode_unreserved_char(i8 signext %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = load i8, i8* %5
%13 = load i8**, i8*** %6
%14 = load i8*, i8** %7
%15 = call i32 @add_untransformed_char(i8 signext %12, i8** %13, i8* %14)
store i32 %15, i32* %4
br label %29
16: ; preds = %3
%17 = load i8, i8* %5
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %7
%23 = call i32 @add_untransformed_char(i8 signext 43, i8** %21, i8* %22)
store i32 %23, i32* %4
br label %29
24: ; preds = %16
%25 = load i8, i8* %5
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %7
%28 = call i32 @add_percent_encoded_char(i8 signext %25, i8** %26, i8* %27)
store i32 %28, i32* %4
br label %29
29: ; preds = %24, %20, %11
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @add_url_encoded_char(i8 signext %0, i8** %1, i8* %2) {
%4 = tail call i64 @is_url_encode_unreserved_char(i8 signext %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @add_untransformed_char(i8 signext %0, i8** %1, i8* %2)
br label %14
8: ; preds = %3
%9 = icmp eq i8 %0, 32
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @add_untransformed_char(i8 signext 43, i8** %1, i8* %2)
br label %14
12: ; preds = %8
%13 = tail call i32 @add_percent_encoded_char(i8 signext %0, i8** %1, i8* %2)
br label %14
14: ; preds = %12, %10, %6
%15 = phi i32 [ %7, %6 ], [ %11, %10 ], [ %13, %12 ]
ret i32 %15
}