#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 decode_ch(int, int, char);
int /*<<< orphan*/ printf(char *, ...);
void show_string(int index, int offset, const char *value, bool is_encoded) {
  printf("[%d] offset=%d", index, offset);
  printf(" ");
  printf("\"");
  int i = 0;
  while (true) {
    char ch = value[i];
    if (is_encoded) {
      ch = decode_ch(offset, i, ch);
    }
    if (ch == '\0') {
      break;
    }
    if (ch == '"') {
      printf("\\\"");
    } else if (ch == '\r') {
      printf("\\r");
    } else if (ch == '\n') {
      printf("\\n");
    } else {
      printf("%c", ch);
    }
    ++i;
  }
  printf("\"");
  printf("\n");
}


x86 assembly (clang, -O0):
<show_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1196 <show_string+0x76>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
movsbl -0x19(%rbp),%edx
call   1040 <decode_ch@plt>
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    11a8 <show_string+0x88>
jmp    1232 <show_string+0x112>
movsbl -0x19(%rbp),%eax
cmp    $0x22,%eax
jne    11c8 <show_string+0xa8>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1224 <show_string+0x104>
movsbl -0x19(%rbp),%eax
cmp    $0xd,%eax
jne    11e8 <show_string+0xc8>
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121f <show_string+0xff>
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1208 <show_string+0xe8>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121a <show_string+0xfa>
movsbl -0x19(%rbp),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121f <show_string+0xff>
jmp    1224 <show_string+0x104>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116c <show_string+0x4c>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%esi
lea    0xf40(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x22,%edi
call   1030 <putchar@plt>
lea    0xe8f(%rip),%r12
lea    0xf23(%rip),%r13
xor    %r15d,%r15d
jmp    118e <show_string+0x5e>
nopl   (%rax)
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
movzbl (%rbx,%r15,1),%eax
test   %ebp,%ebp
je     11a5 <show_string+0x75>
movsbl %al,%edx
mov    %r14d,%edi
mov    %r15d,%esi
call   1050 <decode_ch@plt>
cmp    $0x22,%al
ja     11c0 <show_string+0x90>
movzbl %al,%ecx
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
lea    0xee5(%rip),%rdi
jmp    1183 <show_string+0x53>
xchg   %ax,%ax
movsbl %al,%edi
call   1030 <putchar@plt>
add    $0x1,%r15
jmp    118e <show_string+0x5e>
xchg   %ax,%ax
lea    0xec7(%rip),%rdi
jmp    1183 <show_string+0x53>
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [15 x i8] c"[%d] offset=%d\00"
@.str.3 = [3 x i8] c"\\\22\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\n\00"
define void @show_string(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%6 = tail call i32 @putchar(i32 32)
%7 = tail call i32 @putchar(i32 34)
%8 = icmp eq i32 %3, 0
br label %9
9: ; preds = %27, %4
%10 = phi i64 [ %28, %27 ], [ 0, %4 ]
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = load i8, i8* %11
br i1 %8, label %16, label %13
13: ; preds = %9
%14 = trunc i64 %10 to i32
%15 = tail call signext i8 @decode_ch(i32 %1, i32 %14, i8 signext %12)
br label %16
16: ; preds = %13, %9
%17 = phi i8 [ %15, %13 ], [ %12, %9 ]
switch i8 %17, label %24 [
i8 0, label %29
i8 34, label %18
i8 13, label %20
i8 10, label %22
]
18: ; preds = %16
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %27
20: ; preds = %16
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %27
22: ; preds = %16
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %27
24: ; preds = %16
%25 = sext i8 %17 to i32
%26 = tail call i32 @putchar(i32 %25)
br label %27
27: ; preds = %18, %22, %24, %20
%28 = add nuw i64 %10, 1
br label %9
29: ; preds = %16
%30 = tail call i32 @putchar(i32 34)
%31 = tail call i32 @putchar(i32 10)
ret void
}