#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*/ ack_printf(char *, int);
int /*<<< orphan*/ ack_putchar(int);
void ack_put_string(const char *s, size_t n) {
  while (n > 0) {
    int c = *s;
    if (c < ' ' || c > 0177) {
      ack_printf("\\%03o", c & 0xFF);
    } else if (c == '"' || c == '\\') {
      ack_printf("\\%c", c);
    } else {
      ack_putchar(c);
    }
    s++;
    n--;
  }
}


x86 assembly (clang, -O0):
<ack_put_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    11c5 <ack_put_string+0xa5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x20,-0x14(%rbp)
jl     1159 <ack_put_string+0x39>
cmpl   $0x7f,-0x14(%rbp)
jle    1173 <ack_put_string+0x53>
mov    -0x14(%rbp),%esi
and    $0xff,%esi
lea    0xe97(%rip),%rdi
call   1030 <ack_printf@plt>
jmp    11a8 <ack_put_string+0x88>
cmpl   $0x22,-0x14(%rbp)
je     1187 <ack_put_string+0x67>
cmpl   $0x5c,-0x14(%rbp)
jne    119b <ack_put_string+0x7b>
mov    -0x14(%rbp),%esi
lea    0xe75(%rip),%rdi
call   1030 <ack_printf@plt>
jmp    11a3 <ack_put_string+0x83>
mov    -0x14(%rbp),%edi
call   1040 <ack_putchar@plt>
jmp    11a8 <ack_put_string+0x88>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <ack_put_string+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ack_put_string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     1189 <ack_put_string+0x69>
mov    %rsi,%r13
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xec3(%rip),%r15
lea    0xec2(%rip),%r12
jmp    1165 <ack_put_string+0x45>
cs nopw 0x0(%rax,%rax,1)
movzbl %sil,%esi
mov    %r15,%rdi
call   1030 <ack_printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     1189 <ack_put_string+0x69>
movsbl (%r14,%rbx,1),%esi
cmp    $0x1f,%esi
jle    1150 <ack_put_string+0x30>
cmp    $0x5c,%sil
je     117b <ack_put_string+0x5b>
cmp    $0x22,%sil
jne    1180 <ack_put_string+0x60>
mov    %r12,%rdi
jmp    1157 <ack_put_string+0x37>
mov    %esi,%edi
call   1040 <ack_putchar@plt>
jmp    115c <ack_put_string+0x3c>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"\\%03o\00"
@.str.1 = [4 x i8] c"\\%c\00"
define void @ack_put_string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %6
6: ; preds = %35, %2
%7 = load i64, i64* %4
%8 = icmp ugt i64 %7, 0
br i1 %8, label %9, label %40
9: ; preds = %6
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 32
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = load i32, i32* %5
%17 = icmp sgt i32 %16, 127
br i1 %17, label %18, label %22
18: ; preds = %15, %9
%19 = load i32, i32* %5
%20 = and i32 %19, 255
%21 = call i32 @ack_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %35
22: ; preds = %15
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, 34
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 92
br i1 %27, label %28, label %31
28: ; preds = %25, %22
%29 = load i32, i32* %5
%30 = call i32 @ack_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %29)
br label %34
31: ; preds = %25
%32 = load i32, i32* %5
%33 = call i32 @ack_putchar(i32 %32)
br label %34
34: ; preds = %31, %28
br label %35
35: ; preds = %34, %18
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
%38 = load i64, i64* %4
%39 = add i64 %38, -1
store i64 %39, i64* %4
br label %6
40: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"\\%03o\00"
@.str.1 = [4 x i8] c"\\%c\00"
define void @ack_put_string(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %22, label %4
4: ; preds = %2, %18
%5 = phi i8* [ %19, %18 ], [ %0, %2 ]
%6 = phi i64 [ %20, %18 ], [ %1, %2 ]
%7 = load i8, i8* %5
%8 = sext i8 %7 to i32
%9 = icmp slt i8 %7, 32
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = and i32 %8, 255
%12 = tail call i32 @ack_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %18
13: ; preds = %4
switch i8 %7, label %16 [
i8 92, label %14
i8 34, label %14
]
14: ; preds = %13, %13
%15 = tail call i32 @ack_printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %18
16: ; preds = %13
%17 = tail call i32 @ack_putchar(i32 %8)
br label %18
18: ; preds = %14, %16, %10
%19 = getelementptr inbounds i8, i8* %5, i64 1
%20 = add i64 %6, -1
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %18, %2
ret void
}