#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
long test_time();
char *url_encode(char const *);
void test_encode_url(const char *url, const char *res) {
  printf(" checking %s\n", url);
  long est = 0;
  est = test_time();
  char *url_esc = url_encode(url);
  {
    unsigned int i = 0;
    do {
      if (url_esc[i] != res[i]) {
        printf(
            " [\033[1;31mfailed\033[0m] expected '%s', but was '%s'(%s:%d)\n",
            res, url_esc,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/vitalikp/timezero/refs/heads/0.5/test/"
            "test_url.c",
            13);
        exit(0);
      }
    } while (url_esc[i++] != '\0');
  };
  est = test_time() - est;
  printf(" [\033[1;32mpassed\033[0m] %lu ms\n", est);
}


x86 assembly (clang, -O0):
<test_encode_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <test_time@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <url_encode@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%rcx
mov    -0x24(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11d1 <test_encode_url+0x91>
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe58(%rip),%rdi
lea    0xe8a(%rip),%rcx
mov    $0xd,%r8d
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
jmp    11d6 <test_encode_url+0x96>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x24(%rbp)
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1189 <test_encode_url+0x49>
mov    $0x0,%al
call   1040 <test_time@plt>
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_encode_url>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xeac(%rip),%rdi
xor    %ebp,%ebp
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <test_time@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <url_encode@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edx
movzbl (%rax,%rdx,1),%ecx
cmp    (%rbx,%rdx,1),%cl
jne    11b7 <test_encode_url+0x77>
add    $0x1,%ebp
test   %cl,%cl
jne    1180 <test_encode_url+0x40>
xor    %eax,%eax
call   1040 <test_time@plt>
sub    %r14,%rax
lea    0xf2f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xe82(%rip),%rcx
mov    %rbx,%rsi
mov    %rax,%rdx
mov    $0xd,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c" checking %s\0A\00"
@.str.1 = [57 x i8] c" [\1B[1;31mfailed\1B[0m] expected '%s', but was '%s'(%s:%d)\0A\00"
@.str.2 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/vitalikp/timezero/refs/heads/0.5/test/test_url.c\00"
@.str.3 = [29 x i8] c" [\1B[1;32mpassed\1B[0m] %lu ms\0A\00"
define void @test_encode_url(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %8)
store i64 0, i64* %5
%10 = call i64 (...) @test_time()
store i64 %10, i64* %5
%11 = load i8*, i8** %3
%12 = call i8* @url_encode(i8* %11)
store i8* %12, i8** %6
store i32 0, i32* %7
br label %13
13: ; preds = %33, %2
%14 = load i8*, i8** %6
%15 = load i32, i32* %7
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = load i8*, i8** %4
%21 = load i32, i32* %7
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %19, %25
br i1 %26, label %27, label %32
27: ; preds = %13
%28 = load i8*, i8** %4
%29 = load i8*, i8** %6
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.2, i64 0, i64 0), i32 13)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %13
br label %33
33: ; preds = %32
%34 = load i8*, i8** %6
%35 = load i32, i32* %7
%36 = add i32 %35, 1
store i32 %36, i32* %7
%37 = zext i32 %35 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %13, label %42
42: ; preds = %33
%43 = call i64 (...) @test_time()
%44 = load i64, i64* %5
%45 = sub nsw i64 %43, %44
store i64 %45, i64* %5
%46 = load i64, i64* %5
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %46)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c" checking %s\0A\00"
@.str.1 = [57 x i8] c" [\1B[1;31mfailed\1B[0m] expected '%s', but was '%s'(%s:%d)\0A\00"
@.str.2 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/vitalikp/timezero/refs/heads/0.5/test/test_url.c\00"
@.str.3 = [29 x i8] c" [\1B[1;32mpassed\1B[0m] %lu ms\0A\00"
define void @test_encode_url(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i64 (...) @test_time()
%5 = tail call i8* @url_encode(i8* %0)
br label %6
6: ; preds = %17, %2
%7 = phi i32 [ 0, %2 ], [ %18, %17 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = load i8, i8* %9
%11 = getelementptr inbounds i8, i8* %1, i64 %8
%12 = load i8, i8* %11
%13 = icmp eq i8 %10, %12
br i1 %13, label %17, label %14
14: ; preds = %6
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %5, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.2, i64 0, i64 0), i32 13)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %6
%18 = add i32 %7, 1
%19 = icmp eq i8 %10, 0
br i1 %19, label %20, label %6
20: ; preds = %17
%21 = tail call i64 (...) @test_time()
%22 = sub nsw i64 %21, %4
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i64 %22)
ret void
}