#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 */
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const);
int strlen(char const *);
char *encode_label(const char *label) {
  char *str, *c;
  int i;
  str = malloc(strlen(label) * 4 + 1);
  c = str;
  for (i = 0; i < strlen(label); i++) {
    if (label[i] == '/' || label[i] == '\\') {
      sprintf(c, "\\x%02x", label[i]);
      c += 4;
      continue;
    }
    *(c++) = label[i];
  }
  *c = '\0';
  return str;
}


x86 assembly (clang, -O0):
<encode_label>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x2,%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1202 <encode_label+0xd2>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     11ab <encode_label+0x7b>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
jne    11d8 <encode_label+0xa8>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe42(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1050 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    11f4 <encode_label+0xc4>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <encode_label+0x35>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_label>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(,%rax,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %r14,%r13
test   %eax,%eax
jle    11ac <encode_label+0x7c>
xor    %ebx,%ebx
lea    0xe98(%rip),%r12
mov    %r14,%r13
jmp    1195 <encode_label+0x65>
nopl   (%rax)
movsbl %al,%edx
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <sprintf@plt>
add    $0x4,%r13
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11ac <encode_label+0x7c>
movzbl (%r15,%rbx,1),%eax
cmp    $0x5c,%al
je     1170 <encode_label+0x40>
cmp    $0x2f,%al
je     1170 <encode_label+0x40>
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    1182 <encode_label+0x52>
movb   $0x0,0x0(%r13)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\\x%02x\00"
define i8* @encode_label(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = mul nsw i32 %7, 4
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
store i8* %11, i8** %4
store i32 0, i32* %5
br label %12
12: ; preds = %51, %1
%13 = load i32, i32* %5
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %54
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 47
br i1 %24, label %33, label %25
25: ; preds = %17
%26 = load i8*, i8** %2
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 92
br i1 %32, label %33, label %43
33: ; preds = %25, %17
%34 = load i8*, i8** %4
%35 = load i8*, i8** %2
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %39)
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i64 4
store i8* %42, i8** %4
br label %51
43: ; preds = %25
%44 = load i8*, i8** %2
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %4
store i8 %48, i8* %49
br label %51
51: ; preds = %43, %33
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
br label %12
54: ; preds = %12
%55 = load i8*, i8** %4
store i8 0, i8* %55
%56 = load i8*, i8** %3
ret i8* %56
}

LLVM IR (-O2):
@.str = [7 x i8] c"\\x%02x\00"
define noalias i8* @encode_label(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 2
%4 = or i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %1, %18
%9 = phi i64 [ %20, %18 ], [ 0, %1 ]
%10 = phi i8* [ %19, %18 ], [ %5, %1 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
switch i8 %12, label %16 [
i8 47, label %13
i8 92, label %13
]
13: ; preds = %8, %8
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %10, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%15 = getelementptr inbounds i8, i8* %10, i64 4
br label %18
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %12, i8* %10
br label %18
18: ; preds = %16, %13
%19 = phi i8* [ %15, %13 ], [ %17, %16 ]
%20 = add nuw nsw i64 %9, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %18, %1
%25 = phi i8* [ %5, %1 ], [ %19, %18 ]
store i8 0, i8* %25
ret i8* %5
}