char *httpd_binary_encode(const char *val) {
  char *buf =
      (char *)aMalloc_(strlen(val) * 3 + 1,
                       "/scratch/repos/new/home/jordi_armengol_estape/"
                       "c-scraper/outputs/2022-01-22/02-19-57/repos/Lilystar/"
                       "Auriga/refs/heads/master/src/common/httpd.c",
                       3078, __FUNCTION__);
  char *p = buf;
  while (*val) {
    if (isalnum((unsigned char)*val)) {
      *(p++) = *(val++);
    } else {
      unsigned char c1 = *(val++);
      unsigned char c2 = (c1 >> 4);
      unsigned char c3 = (c1 & 0x0F);
      *(p++) = '%';
      *(p++) = c2 + (c2 >= 10 ? 'A' - 10 : '0');
      *(p++) = c3 + (c3 >= 10 ? 'A' - 10 : '0');
    }
  }
  *p = 0;
  return buf;
}


x86 assembly (clang, -O0):
<httpd_binary_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
imul   $0x3,%rax,%rdi
add    $0x1,%rdi
lea    0xeac(%rip),%rsi
mov    $0xc06,%edx
lea    0xf2f(%rip),%rcx
mov    $0x0,%al
call   1050 <aMalloc_@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1257 <httpd_binary_encode+0x127>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%eax
je     11be <httpd_binary_encode+0x8e>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1252 <httpd_binary_encode+0x122>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movzbl -0x19(%rbp),%eax
sar    $0x4,%eax
mov    %al,-0x1a(%rbp)
movzbl -0x19(%rbp),%eax
and    $0xf,%eax
mov    %al,-0x1b(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x25,(%rax)
movzbl -0x1a(%rbp),%eax
movzbl -0x1a(%rbp),%esi
mov    $0x30,%ecx
mov    $0x37,%edx
cmp    $0xa,%esi
cmovge %edx,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movzbl -0x1b(%rbp),%eax
movzbl -0x1b(%rbp),%esi
mov    $0x30,%ecx
mov    $0x37,%edx
cmp    $0xa,%esi
cmovge %edx,%ecx
add    %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1175 <httpd_binary_encode+0x45>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpd_binary_encode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    (%rax,%rax,2),%rdi
add    $0x1,%rdi
lea    0xeb1(%rip),%rsi
lea    0xf39(%rip),%rcx
mov    $0xc06,%edx
xor    %eax,%eax
call   1050 <aMalloc_@plt>
movslq %eax,%r14
mov    0x0(%rbp),%bl
mov    %r14,%r15
test   %bl,%bl
je     11d7 <httpd_binary_encode+0xa7>
add    $0x1,%rbp
mov    $0x37,%r12d
mov    %r14,%r15
jmp    11c2 <httpd_binary_encode+0x92>
xchg   %ax,%ax
mov    %ebx,%eax
shr    $0x4,%al
mov    %ebx,%ecx
and    $0xf,%cl
movb   $0x25,(%r15)
cmp    $0xa0,%bl
mov    $0x30,%edx
cmovae %r12d,%edx
add    %al,%dl
cmp    $0xa,%cl
mov    $0x30,%eax
cmovae %r12d,%eax
mov    %dl,0x1(%r15)
add    %cl,%al
mov    %al,0x2(%r15)
add    $0x3,%r15
movzbl 0x0(%rbp),%ebx
add    $0x1,%rbp
test   %bl,%bl
je     11d7 <httpd_binary_encode+0xa7>
movzbl %bl,%edi
call   1040 <isalnum@plt>
test   %eax,%eax
je     1180 <httpd_binary_encode+0x50>
mov    %bl,(%r15)
add    $0x1,%r15
jmp    11b6 <httpd_binary_encode+0x86>
movb   $0x0,(%r15)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Lilystar/Auriga/refs/heads/master/src/common/httpd.c\00"
@__FUNCTION__.httpd_binary_encode = [20 x i8] c"httpd_binary_encode\00"
define i8* @httpd_binary_encode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = mul i64 %9, 3
%11 = add i64 %10, 1
%12 = call i32 (i64, i8*, i32, i8*, ...) bitcast (i32 (...)* @aMalloc_ to i32 (i64, i8*, i32, i8*, ...)*)(i64 %11, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i32 3078, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__FUNCTION__.httpd_binary_encode, i64 0, i64 0))
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %3
%15 = load i8*, i8** %3
store i8* %15, i8** %4
br label %16
16: ; preds = %68, %1
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %69
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 @isalnum(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %2
%29 = load i8, i8* %27
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
store i8 %29, i8* %30
br label %68
32: ; preds = %20
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %2
%35 = load i8, i8* %33
store i8 %35, i8* %5
%36 = load i8, i8* %5
%37 = zext i8 %36 to i32
%38 = ashr i32 %37, 4
%39 = trunc i32 %38 to i8
store i8 %39, i8* %6
%40 = load i8, i8* %5
%41 = zext i8 %40 to i32
%42 = and i32 %41, 15
%43 = trunc i32 %42 to i8
store i8 %43, i8* %7
%44 = load i8*, i8** %4
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %4
store i8 37, i8* %44
%46 = load i8, i8* %6
%47 = zext i8 %46 to i32
%48 = load i8, i8* %6
%49 = zext i8 %48 to i32
%50 = icmp sge i32 %49, 10
%51 = zext i1 %50 to i64
%52 = select i1 %50, i32 55, i32 48
%53 = add nsw i32 %47, %52
%54 = trunc i32 %53 to i8
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
store i8 %54, i8* %55
%57 = load i8, i8* %7
%58 = zext i8 %57 to i32
%59 = load i8, i8* %7
%60 = zext i8 %59 to i32
%61 = icmp sge i32 %60, 10
%62 = zext i1 %61 to i64
%63 = select i1 %61, i32 55, i32 48
%64 = add nsw i32 %58, %63
%65 = trunc i32 %64 to i8
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %4
store i8 %65, i8* %66
br label %68
68: ; preds = %32, %26
br label %16
69: ; preds = %16
%70 = load i8*, i8** %4
store i8 0, i8* %70
%71 = load i8*, i8** %3
ret i8* %71
}

LLVM IR (-O2):
@.str = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Lilystar/Auriga/refs/heads/master/src/common/httpd.c\00"
@__FUNCTION__.httpd_binary_encode = [20 x i8] c"httpd_binary_encode\00"
define i8* @httpd_binary_encode(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = mul i64 %2, 3
%4 = add i64 %3, 1
%5 = tail call i32 (i64, i8*, i32, i8*, ...) bitcast (i32 (...)* @aMalloc_ to i32 (i64, i8*, i32, i8*, ...)*)(i64 %4, i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str, i64 0, i64 0), i32 3078, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__FUNCTION__.httpd_binary_encode, i64 0, i64 0))
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i8*
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %36, label %10
10: ; preds = %1, %31
%11 = phi i8 [ %34, %31 ], [ %8, %1 ]
%12 = phi i8* [ %33, %31 ], [ %0, %1 ]
%13 = phi i8* [ %32, %31 ], [ %7, %1 ]
%14 = zext i8 %11 to i32
%15 = tail call i32 @isalnum(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %10
%18 = getelementptr inbounds i8, i8* %13, i64 1
store i8 %11, i8* %13
br label %31
19: ; preds = %10
%20 = lshr i8 %11, 4
%21 = and i8 %11, 15
%22 = getelementptr inbounds i8, i8* %13, i64 1
store i8 37, i8* %13
%23 = icmp ugt i8 %11, -97
%24 = select i1 %23, i8 55, i8 48
%25 = add nuw nsw i8 %24, %20
%26 = getelementptr inbounds i8, i8* %13, i64 2
store i8 %25, i8* %22
%27 = icmp ugt i8 %21, 9
%28 = select i1 %27, i8 55, i8 48
%29 = add nuw nsw i8 %28, %21
%30 = getelementptr inbounds i8, i8* %13, i64 3
store i8 %29, i8* %26
br label %31
31: ; preds = %19, %17
%32 = phi i8* [ %18, %17 ], [ %30, %19 ]
%33 = getelementptr inbounds i8, i8* %12, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %10
36: ; preds = %31, %1
%37 = phi i8* [ %7, %1 ], [ %32, %31 ]
store i8 0, i8* %37
ret i8* %7
}