#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*/ uint8_to_octal_chars(char, char *);
bool add_octal_escape(char ch, char **buffer, char *buffer_end) {
  if (buffer_end - *buffer < 4)
    return false;
  char octal_chars[4];
  uint8_to_octal_chars(ch, octal_chars);
  *(*buffer)++ = '\\';
  *(*buffer)++ = octal_chars[0];
  *(*buffer)++ = octal_chars[1];
  *(*buffer)++ = octal_chars[2];
  return true;
}


x86 assembly (clang, -O0):
<add_octal_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
cmp    $0x4,%rax
jge    114a <add_octal_escape+0x3a>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <add_octal_escape+0xa6>
mov    -0x5(%rbp),%al
lea    -0x1c(%rbp),%rsi
movsbl %al,%edi
call   1030 <uint8_to_octal_chars@plt>
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movb   $0x5c,(%rax)
mov    -0x1c(%rbp),%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x1b(%rbp),%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
mov    -0x1a(%rbp),%cl
mov    -0x10(%rbp),%rdx
mov    (%rdx),%rax
mov    %rax,%rsi
add    $0x1,%rsi
mov    %rsi,(%rdx)
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_octal_escape>:
push   %rbx
sub    $0x10,%rsp
sub    (%rsi),%rdx
xor    %eax,%eax
cmp    $0x4,%rdx
jl     1173 <add_octal_escape+0x63>
mov    %rsi,%rbx
movsbl %dil,%edi
lea    0xc(%rsp),%rsi
call   1030 <uint8_to_octal_chars@plt>
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movb   $0x5c,(%rax)
mov    0xc(%rsp),%al
mov    (%rbx),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %al,(%rcx)
mov    0xd(%rsp),%al
mov    (%rbx),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %al,(%rcx)
mov    0xe(%rsp),%al
mov    (%rbx),%rcx
lea    0x1(%rcx),%rdx
mov    %rdx,(%rbx)
mov    %al,(%rcx)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @add_octal_escape(i8 signext %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca [4 x i8]
store i8 %0, i8* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %7
%10 = load i8**, i8*** %6
%11 = load i8*, i8** %10
%12 = ptrtoint i8* %9 to i64
%13 = ptrtoint i8* %11 to i64
%14 = sub i64 %12, %13
%15 = icmp slt i64 %14, 4
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 0, i32* %4
br label %39
17: ; preds = %3
%18 = load i8, i8* %5
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%20 = call i32 @uint8_to_octal_chars(i8 signext %18, i8* %19)
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %21
store i8 92, i8* %22
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%25 = load i8, i8* %24
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %26
store i8 %25, i8* %27
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
%30 = load i8, i8* %29
%31 = load i8**, i8*** %6
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
store i8 %30, i8* %32
%34 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
%35 = load i8, i8* %34
%36 = load i8**, i8*** %6
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %36
store i8 %35, i8* %37
store i32 1, i32* %4
br label %39
39: ; preds = %17, %16
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @add_octal_escape(i8 signext %0, i8** nocapture %1, i8* %2) {
%4 = alloca [4 x i8]
%5 = load i8*, i8** %1
%6 = ptrtoint i8* %2 to i64
%7 = ptrtoint i8* %5 to i64
%8 = sub i64 %6, %7
%9 = icmp slt i64 %8, 4
br i1 %9, label %26, label %10
10: ; preds = %3
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%12 = call i32 @uint8_to_octal_chars(i8 signext %0, i8* %11)
%13 = load i8*, i8** %1
%14 = getelementptr inbounds i8, i8* %13, i64 1
store i8* %14, i8** %1
store i8 92, i8* %13
%15 = load i8, i8* %11
%16 = load i8*, i8** %1
%17 = getelementptr inbounds i8, i8* %16, i64 1
store i8* %17, i8** %1
store i8 %15, i8* %16
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 1
%19 = load i8, i8* %18
%20 = load i8*, i8** %1
%21 = getelementptr inbounds i8, i8* %20, i64 1
store i8* %21, i8** %1
store i8 %19, i8* %20
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 2
%23 = load i8, i8* %22
%24 = load i8*, i8** %1
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %1
store i8 %23, i8* %24
br label %26
26: ; preds = %3, %10
%27 = phi i32 [ 1, %10 ], [ 0, %3 ]
ret i32 %27
}