#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*/ sprintf(char *, char *, char);
int /*<<< orphan*/ str_insertChar(char *, char);
char *strchr(char *, int);
void str_encodeChar(char *pStr, int c) {
  while ((pStr = strchr(pStr, c)) != 0) {
    char sHexCode[4];
    sprintf(sHexCode, "%2.2x", *pStr);
    *pStr++ = '%';
    str_insertChar(pStr, sHexCode[1]);
    str_insertChar(pStr, sHexCode[0]);
    pStr += 2;
  }
}


x86 assembly (clang, -O0):
<str_encodeChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <strchr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11ad <str_encodeChar+0x7d>
lea    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
lea    0xe98(%rip),%rsi
movsbl (%rax),%edx
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x25,(%rax)
mov    -0x8(%rbp),%rdi
movsbl -0xf(%rbp),%esi
call   1040 <str_insertChar@plt>
mov    -0x8(%rbp),%rdi
movsbl -0x10(%rbp),%esi
call   1040 <str_insertChar@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    113f <str_encodeChar+0xf>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_encodeChar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r12d
call   1030 <strchr@plt>
test   %rax,%rax
je     11a6 <str_encodeChar+0x76>
mov    %rax,%rbx
lea    0xead(%rip),%r14
lea    0xc(%rsp),%r15
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x1(%rbx),%rbp
movb   $0x25,(%rbx)
movsbl 0xd(%rsp),%esi
mov    %rbp,%rdi
call   1040 <str_insertChar@plt>
movsbl 0xc(%rsp),%esi
mov    %rbp,%rdi
call   1040 <str_insertChar@plt>
add    $0x3,%rbx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1030 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1160 <str_encodeChar+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%2.2x\00"
define void @str_encodeChar(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [4 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
br label %6
6: ; preds = %11, %2
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i8* @strchr(i8* %7, i32 %8)
store i8* %9, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %28
11: ; preds = %6
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %14)
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
store i8 37, i8* %16
%18 = load i8*, i8** %3
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%20 = load i8, i8* %19
%21 = call i32 @str_insertChar(i8* %18, i8 signext %20)
%22 = load i8*, i8** %3
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%24 = load i8, i8* %23
%25 = call i32 @str_insertChar(i8* %22, i8 signext %24)
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 2
store i8* %27, i8** %3
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2.2x\00"
define void @str_encodeChar(i8* %0, i32 %1) {
%3 = alloca [4 x i8]
%4 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
br label %9
9: ; preds = %6, %9
%10 = phi i8* [ %4, %6 ], [ %19, %9 ]
%11 = load i8, i8* %10
%12 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%13 = getelementptr inbounds i8, i8* %10, i64 1
store i8 37, i8* %10
%14 = load i8, i8* %8
%15 = tail call i32 @str_insertChar(i8* %13, i8 signext %14)
%16 = load i8, i8* %7
%17 = tail call i32 @str_insertChar(i8* %13, i8 signext %16)
%18 = getelementptr inbounds i8, i8* %10, i64 3
%19 = tail call i8* @strchr(i8* dereferenceable(1) %18, i32 %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %9
21: ; preds = %9, %2
ret void
}