#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 strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int show_value(char *val, char *buf, int bsize) {
  if (!val) {
    return -5;
  }
  char *dest = buf;
  char *ptr = val;
  while ('\0' != *ptr) {
    if (!strncmp(ptr, "0x5E", 4)) {
      *dest++ = '^';
      ptr += 4;
    } else if (!strncmp(ptr, "0x7C", 4)) {
      *dest++ = '|';
      ptr += 4;
    } else {
      *dest++ = *ptr++;
    }
  }
  return strlen(buf);
}


x86 assembly (clang, -O0):
<show_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114a <show_value+0x2a>
movl   $0xfffffffb,-0x4(%rbp)
jmp    1225 <show_value+0x105>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1219 <show_value+0xf9>
mov    -0x30(%rbp),%rdi
lea    0xe8a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ac <show_value+0x8c>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x5e,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    1214 <show_value+0xf4>
mov    -0x30(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ed <show_value+0xcd>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x7c,(%rax)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
jmp    120f <show_value+0xef>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1214 <show_value+0xf4>
jmp    115a <show_value+0x3a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_value>:
test   %rdi,%rdi
je     11ba <show_value+0x9a>
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r13
cmpb   $0x0,(%rdi)
je     11a9 <show_value+0x89>
lea    0xebc(%rip),%r15
lea    0xeba(%rip),%r12
mov    %r14,%rbx
jmp    1166 <show_value+0x46>
movzbl 0x0(%r13),%eax
add    $0x1,%r13
mov    %al,(%rbx)
add    $0x1,%rbx
cmpb   $0x0,0x0(%r13)
je     11a9 <show_value+0x89>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11a0 <show_value+0x80>
mov    %r13,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1150 <show_value+0x30>
movb   $0x7c,(%rbx)
jmp    11a3 <show_value+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movb   $0x5e,(%rbx)
add    $0x4,%r13
jmp    115b <show_value+0x3b>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <strlen@plt>
mov    $0xfffffffb,%eax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0x5E\00"
@.str.1 = [5 x i8] c"0x7C\00"
define i32 @show_value(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 -5, i32* %4
br label %50
13: ; preds = %3
%14 = load i8*, i8** %6
store i8* %14, i8** %8
%15 = load i8*, i8** %5
store i8* %15, i8** %9
br label %16
16: ; preds = %46, %13
%17 = load i8*, i8** %9
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 0, %19
br i1 %20, label %21, label %47
21: ; preds = %16
%22 = load i8*, i8** %9
%23 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%24 = icmp ne i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %21
%26 = load i8*, i8** %8
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %8
store i8 94, i8* %26
%28 = load i8*, i8** %9
%29 = getelementptr inbounds i8, i8* %28, i64 4
store i8* %29, i8** %9
br label %46
30: ; preds = %21
%31 = load i8*, i8** %9
%32 = call i32 @strncmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
store i8 124, i8* %35
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 4
store i8* %38, i8** %9
br label %45
39: ; preds = %30
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %9
%42 = load i8, i8* %40
%43 = load i8*, i8** %8
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %8
store i8 %42, i8* %43
br label %45
45: ; preds = %39, %34
br label %46
46: ; preds = %45, %25
br label %16
47: ; preds = %16
%48 = load i8*, i8** %6
%49 = call i32 @strlen(i8* %48)
store i32 %49, i32* %4
br label %50
50: ; preds = %47, %12
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [5 x i8] c"0x5E\00"
@.str.1 = [5 x i8] c"0x7C\00"
define i32 @show_value(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %28, label %8
8: ; preds = %5, %23
%9 = phi i8* [ %24, %23 ], [ %0, %5 ]
%10 = phi i8* [ %25, %23 ], [ %1, %5 ]
%11 = tail call i32 @strncmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
store i8 94, i8* %10
%14 = getelementptr inbounds i8, i8* %9, i64 4
br label %23
15: ; preds = %8
%16 = tail call i32 @strncmp(i8* %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
store i8 124, i8* %10
%19 = getelementptr inbounds i8, i8* %9, i64 4
br label %23
20: ; preds = %15
%21 = getelementptr inbounds i8, i8* %9, i64 1
%22 = load i8, i8* %9
store i8 %22, i8* %10
br label %23
23: ; preds = %18, %20, %13
%24 = phi i8* [ %21, %20 ], [ %19, %18 ], [ %14, %13 ]
%25 = getelementptr inbounds i8, i8* %10, i64 1
%26 = load i8, i8* %24
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %8
28: ; preds = %23, %5
%29 = tail call i32 @strlen(i8* %1)
br label %30
30: ; preds = %3, %28
%31 = phi i32 [ %29, %28 ], [ -5, %3 ]
ret i32 %31
}