#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*/ put_hex(char);
int /*<<< orphan*/ write(int, char *, int);
int my_showstr(char *str) {
  int i;
  i = 0;
  while (str[i]) {
    if (str[i] < 32 || str[i] == 127) {
      write(1, "\\", 1);
      put_hex(str[i]);
    } else
      write(1, &str[i], 1);
    ++i;
  }
}


x86 assembly (clang, -O0):
<my_showstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11bd <my_showstr+0x9d>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     116f <my_showstr+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jne    1198 <my_showstr+0x78>
mov    $0x1,%edx
lea    0xe85(%rip),%rsi
mov    %edx,%edi
call   1040 <write@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <put_hex@plt>
jmp    11af <my_showstr+0x8f>
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
mov    $0x1,%edx
mov    %edx,%edi
call   1040 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1133 <my_showstr+0x13>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_showstr>:
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     117b <my_showstr+0x5b>
mov    %rdi,%rbx
lea    0xecc(%rip),%r14
jmp    1159 <my_showstr+0x39>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     117b <my_showstr+0x5b>
add    $0x81,%al
mov    $0x1,%edi
cmp    $0xa0,%al
ja     1140 <my_showstr+0x20>
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
movsbl (%rbx),%edi
call   1030 <put_hex@plt>
jmp    114d <my_showstr+0x2d>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\\\00"
define i32 @my_showstr(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1, %16
%5 = phi i64 [ %17, %16 ], [ 0, %1 ]
%6 = phi i8 [ %19, %16 ], [ %2, %1 ]
%7 = phi i8* [ %18, %16 ], [ %0, %1 ]
%8 = add i8 %6, -127
%9 = icmp ult i8 %8, -95
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%12 = load i8, i8* %7
%13 = tail call i32 @put_hex(i8 signext %12)
br label %16
14: ; preds = %4
%15 = tail call i32 @write(i32 1, i8* %7, i32 1)
br label %16
16: ; preds = %14, %10
%17 = add nuw i64 %5, 1
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %4
21: ; preds = %16, %1
ret i32 undef
}