#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 */
typedef scalar_t__ time_t;

/* Variables and functions */
float CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ phe_escape_html(char *, char *, long const);
int /*<<< orphan*/ printf(char *, float);
int /*<<< orphan*/ simple_escape_html(char *, char *, long const);
int strlen(char *);
int main(void) {
  const long input_size =
      strlen("<body>\n"
             "<div>\n"
             "    <h1>Example Domain</h1>\n"
             "    <p>This domain is established to be used for illustrative "
             "examples in documents. You may use this\n"
             "    domain in examples without prior coordination or asking for "
             "permission.</p>\n"
             "    <p><a href=\"http://www.iana.org/domains/example\">More "
             "information...</a></p>\n"
             "</div>\n"
             "aaa&bbb'ccc`ddd{eee}\n"
             "</body>");
  int i;
  char *res;
  int size_of_res =
      sizeof(char) *
          strlen("<body>\n"
                 "<div>\n"
                 "    <h1>Example Domain</h1>\n"
                 "    <p>This domain is established to be used for "
                 "illustrative examples in documents. You may use this\n"
                 "    domain in examples without prior coordination or asking "
                 "for permission.</p>\n"
                 "    <p><a href=\"http://www.iana.org/domains/example\">More "
                 "information...</a></p>\n"
                 "</div>\n"
                 "aaa&bbb'ccc`ddd{eee}\n"
                 "</body>") *
          6 +
      1;
  res = (char *)malloc(size_of_res);
  float phe_elapsed;
  {
    time_t begin = clock();
    for (i = 0; i < 10000000; i++) {
      phe_escape_html(
          res,
          "<body>\n"
          "<div>\n"
          "    <h1>Example Domain</h1>\n"
          "    <p>This domain is established to be used for illustrative "
          "examples in documents. You may use this\n"
          "    domain in examples without prior coordination or asking for "
          "permission.</p>\n"
          "    <p><a href=\"http://www.iana.org/domains/example\">More "
          "information...</a></p>\n"
          "</div>\n"
          "aaa&bbb'ccc`ddd{eee}\n"
          "</body>",
          input_size);
    }
    time_t end = clock();
    phe_elapsed = (float)(end - begin) / CLOCKS_PER_SEC;
    printf("petit-html-escaper: %f [sec]\n", phe_elapsed);
  }
  float simple_elapsed;
  {
    time_t begin = clock();
    for (i = 0; i < 10000000; i++) {
      simple_escape_html(
          res,
          "<body>\n"
          "<div>\n"
          "    <h1>Example Domain</h1>\n"
          "    <p>This domain is established to be used for illustrative "
          "examples in documents. You may use this\n"
          "    domain in examples without prior coordination or asking for "
          "permission.</p>\n"
          "    <p><a href=\"http://www.iana.org/domains/example\">More "
          "information...</a></p>\n"
          "</div>\n"
          "aaa&bbb'ccc`ddd{eee}\n"
          "</body>",
          input_size);
    }
    time_t end = clock();
    simple_elapsed = (float)(end - begin) / CLOCKS_PER_SEC;
    printf("simple-impl: %f [sec]\n", simple_elapsed);
  }
  printf("petit-html-escaper is faster \x1b[1m%f%%\x1b[0m than simple "
         "implementation\n",
         simple_elapsed / phe_elapsed * 100);
  free(res);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7e(%rip),%rdi
call   1050 <strlen@plt>
cltq
mov    %rax,-0x10(%rbp)
lea    0xe6c(%rip),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
imul   $0x6,%rax,%rax
add    $0x1,%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x989680,-0x14(%rbp)
jge    11fb <main+0x8b>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe1c(%rip),%rsi
call   1080 <phe_escape_html@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11cc <main+0x5c>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
sub    -0x30(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2dce(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
lea    0xf29(%rip),%rdi
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x989680,-0x14(%rbp)
jge    1275 <main+0x105>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xda2(%rip),%rsi
call   1070 <simple_escape_html@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1246 <main+0xd6>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2ss %rax,%xmm0
mov    0x2d54(%rip),%rax
divss  (%rax),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x3c(%rbp),%xmm0
lea    0xecd(%rip),%rdi
call   1060 <printf@plt>
movss  -0x3c(%rbp),%xmm0
divss  -0x28(%rbp),%xmm0
movss  0xd40(%rip),%xmm1
mulss  %xmm1,%xmm0
lea    0xec2(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe82(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
movslq %eax,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %eax,%eax
lea    (%rax,%rax,2),%edi
or     $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r12
mov    $0x989680,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <phe_escape_html@plt>
add    $0xffffffff,%ebp
jne    11c0 <main+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r12,%rax
cvtsi2ss %rax,%xmm0
mov    0x2dff(%rip),%r13
divss  0x0(%r13),%xmm0
lea    0xf62(%rip),%rdi
movss  %xmm0,0x4(%rsp)
call   1060 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r15
mov    $0x989680,%ebp
lea    0xded(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <simple_escape_html@plt>
add    $0xffffffff,%ebp
jne    1220 <main+0xb0>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  0x0(%r13),%xmm0
movss  %xmm0,(%rsp)
lea    0xf1f(%rip),%rdi
call   1060 <printf@plt>
movss  (%rsp),%xmm0
divss  0x4(%rsp),%xmm0
mulss  0xd91(%rip),%xmm0
lea    0xf17(%rip),%rdi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [340 x i8] c"<body>\0A<div>\0A <h1>Example Domain</h1>\0A <p>This domain is established to be used for illustrative examples in documents. You may use this\0A domain in examples without prior coordination or asking for permission.</p>\0A <p><a href=\22http://www.iana.org/domains/example\22>More information...</a></p>\0A</div>\0Aaaa&bbb'ccc`ddd{eee}\0A</body>\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.1 = [30 x i8] c"petit-html-escaper: %f [sec]\0A\00"
@.str.2 = [23 x i8] c"simple-impl: %f [sec]\0A\00"
@.str.3 = [70 x i8] c"petit-html-escaper is faster \1B[1m%f%%\1B[0m than simple implementation\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca float
%7 = alloca i64
%8 = alloca i64
%9 = alloca float
%10 = alloca i64
%11 = alloca i64
store i32 0, i32* %1
%12 = call i32 @strlen(i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0))
%13 = sext i32 %12 to i64
store i64 %13, i64* %2
%14 = call i32 @strlen(i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = mul i64 %16, 6
%18 = add i64 %17, 1
%19 = trunc i64 %18 to i32
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %4
%23 = call i64 (...) @clock()
store i64 %23, i64* %7
store i32 0, i32* %3
br label %24
24: ; preds = %31, %0
%25 = load i32, i32* %3
%26 = icmp slt i32 %25, 10000000
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = load i64, i64* %2
%30 = call i32 @phe_escape_html(i8* %28, i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0), i64 %29)
br label %31
31: ; preds = %27
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %24
34: ; preds = %24
%35 = call i64 (...) @clock()
store i64 %35, i64* %8
%36 = load i64, i64* %8
%37 = load i64, i64* %7
%38 = sub nsw i64 %36, %37
%39 = sitofp i64 %38 to float
%40 = load float, float* @CLOCKS_PER_SEC
%41 = fdiv float %39, %40
store float %41, float* %6
%42 = load float, float* %6
%43 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %42)
%44 = call i64 (...) @clock()
store i64 %44, i64* %10
store i32 0, i32* %3
br label %45
45: ; preds = %52, %34
%46 = load i32, i32* %3
%47 = icmp slt i32 %46, 10000000
br i1 %47, label %48, label %55
48: ; preds = %45
%49 = load i8*, i8** %4
%50 = load i64, i64* %2
%51 = call i32 @simple_escape_html(i8* %49, i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0), i64 %50)
br label %52
52: ; preds = %48
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %45
55: ; preds = %45
%56 = call i64 (...) @clock()
store i64 %56, i64* %11
%57 = load i64, i64* %11
%58 = load i64, i64* %10
%59 = sub nsw i64 %57, %58
%60 = sitofp i64 %59 to float
%61 = load float, float* @CLOCKS_PER_SEC
%62 = fdiv float %60, %61
store float %62, float* %9
%63 = load float, float* %9
%64 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), float %63)
%65 = load float, float* %9
%66 = load float, float* %6
%67 = fdiv float %65, %66
%68 = fmul float %67, 1.000000e+02
%69 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), float %68)
%70 = load i8*, i8** %4
%71 = call i32 @free(i8* %70)
ret i32 0
}

LLVM IR (-O2):
@.str = [340 x i8] c"<body>\0A<div>\0A <h1>Example Domain</h1>\0A <p>This domain is established to be used for illustrative examples in documents. You may use this\0A domain in examples without prior coordination or asking for permission.</p>\0A <p><a href=\22http://www.iana.org/domains/example\22>More information...</a></p>\0A</div>\0Aaaa&bbb'ccc`ddd{eee}\0A</body>\00"
@CLOCKS_PER_SEC = global float 0.000000e+00
@.str.1 = [30 x i8] c"petit-html-escaper: %f [sec]\0A\00"
@.str.2 = [23 x i8] c"simple-impl: %f [sec]\0A\00"
@.str.3 = [70 x i8] c"petit-html-escaper is faster \1B[1m%f%%\1B[0m than simple implementation\0A\00"
define i32 @main() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0))
%2 = sext i32 %1 to i64
%3 = tail call i32 @strlen(i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0))
%4 = mul i32 %3, 6
%5 = or i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i64 (...) @clock()
br label %9
9: ; preds = %0, %9
%10 = phi i32 [ 0, %0 ], [ %12, %9 ]
%11 = tail call i32 @phe_escape_html(i8* %7, i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0), i64 %2)
%12 = add nuw nsw i32 %10, 1
%13 = icmp eq i32 %12, 10000000
br i1 %13, label %14, label %9
14: ; preds = %9
%15 = tail call i64 (...) @clock()
%16 = sub nsw i64 %15, %8
%17 = sitofp i64 %16 to float
%18 = load float, float* @CLOCKS_PER_SEC
%19 = fdiv float %17, %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), float %19)
%21 = tail call i64 (...) @clock()
br label %22
22: ; preds = %14, %22
%23 = phi i32 [ 0, %14 ], [ %25, %22 ]
%24 = tail call i32 @simple_escape_html(i8* %7, i8* getelementptr inbounds ([340 x i8], [340 x i8]* @.str, i64 0, i64 0), i64 %2)
%25 = add nuw nsw i32 %23, 1
%26 = icmp eq i32 %25, 10000000
br i1 %26, label %27, label %22
27: ; preds = %22
%28 = tail call i64 (...) @clock()
%29 = sub nsw i64 %28, %21
%30 = sitofp i64 %29 to float
%31 = load float, float* @CLOCKS_PER_SEC
%32 = fdiv float %30, %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), float %32)
%34 = fdiv float %32, %19
%35 = fmul float %34, 1.000000e+02
%36 = tail call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.3, i64 0, i64 0), float %35)
%37 = tail call i32 @free(i8* %7)
ret i32 0
}