#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 *char_to_str(char);
char *malloc(int);
scalar_t__ my_putnbr_base(char, int, int /*<<< orphan*/);
char *my_strcat(char *, char *);
int my_strlen(char *);
char *non_printable_octal(char *str) {
  int i = 0;
  char *ret = malloc(my_strlen(str) * sizeof(char));
  while (str[i]) {
    if (str[i] < 32) {
      ret = my_strcat(my_strcat(ret, "\\0"),
                      (char *)my_putnbr_base(str[i], 8, 0));
    } else {
      ret = my_strcat(ret, char_to_str(str[i]));
    }
    i++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<non_printable_octal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     121c <non_printable_octal+0xcc>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jge    11e5 <non_printable_octal+0x95>
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <my_strcat@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    $0x8,%esi
xor    %edx,%edx
movsbl (%rax,%rcx,1),%edi
call   1040 <my_putnbr_base@plt>
mov    -0x20(%rbp),%rdi
mov    %rax,%rsi
call   1050 <my_strcat@plt>
mov    %rax,-0x18(%rbp)
jmp    120e <non_printable_octal+0xbe>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <char_to_str@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1050 <my_strcat@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <non_printable_octal+0x2d>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<non_printable_octal>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <my_strlen@plt>
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    (%rbx),%al
test   %al,%al
je     11c5 <non_printable_octal+0x75>
add    $0x1,%rbx
lea    0xe88(%rip),%r14
jmp    11a1 <non_printable_octal+0x51>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1070 <char_to_str@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <my_strcat@plt>
mov    %rax,%r15
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11c5 <non_printable_octal+0x75>
cmp    $0x1f,%al
jg     1180 <non_printable_octal+0x30>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <my_strcat@plt>
mov    %rax,%r15
movsbl -0x1(%rbx),%edi
mov    $0x8,%esi
xor    %edx,%edx
call   1040 <my_putnbr_base@plt>
jmp    1188 <non_printable_octal+0x38>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"\\0\00"
define i8* @non_printable_octal(i8* %0) {
%2 = tail call i32 @my_strlen(i8* %0)
%3 = tail call i8* @malloc(i32 %2)
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %27, label %6
6: ; preds = %1, %21
%7 = phi i64 [ %23, %21 ], [ 0, %1 ]
%8 = phi i8 [ %25, %21 ], [ %4, %1 ]
%9 = phi i8* [ %24, %21 ], [ %0, %1 ]
%10 = phi i8* [ %22, %21 ], [ %3, %1 ]
%11 = icmp slt i8 %8, 32
br i1 %11, label %12, label %18
12: ; preds = %6
%13 = tail call i8* @my_strcat(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = load i8, i8* %9
%15 = tail call i64 @my_putnbr_base(i8 signext %14, i32 8, i32 0)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i8* @my_strcat(i8* %13, i8* %16)
br label %21
18: ; preds = %6
%19 = tail call i8* @char_to_str(i8 signext %8)
%20 = tail call i8* @my_strcat(i8* %10, i8* %19)
br label %21
21: ; preds = %18, %12
%22 = phi i8* [ %17, %12 ], [ %20, %18 ]
%23 = add nuw i64 %7, 1
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %6
27: ; preds = %21, %1
%28 = phi i8* [ %3, %1 ], [ %22, %21 ]
ret i8* %28
}