#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*/ printf(char *, int);
void printstring(char *p) {
  int delim = '"';
  printf("%c", delim);
  while (*p) {
    unsigned char c = *p++;
    if (c < ' ' || c == 0177 || c == delim || c == '\\')
      printf("\\%03o", c);
    else
      printf("%c", c);
  }
  printf("%c", delim);
}


x86 assembly (clang, -O0):
<printstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x22,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xed3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b1 <printstring+0xa1>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0x20,%eax
jl     1187 <printstring+0x77>
movzbl -0xd(%rbp),%eax
cmp    $0x7f,%eax
je     1187 <printstring+0x77>
movzbl -0xd(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1187 <printstring+0x77>
movzbl -0xd(%rbp),%eax
cmp    $0x5c,%eax
jne    119c <printstring+0x8c>
movzbl -0xd(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
jmp    11ac <printstring+0x9c>
movzbl -0xd(%rbp),%esi
lea    0xe59(%rip),%rdi
call   1030 <printf@plt>
jmp    1132 <printstring+0x22>
mov    -0xc(%rbp),%esi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printstring>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xee1(%rip),%r14
mov    %r14,%rdi
mov    $0x22,%esi
call   1030 <printf@plt>
mov    (%rbx),%al
test   %al,%al
je     1171 <printstring+0x61>
add    $0x1,%rbx
lea    0xec6(%rip),%r15
jmp    1165 <printstring+0x55>
nop
cmp    $0x5c,%al
cmove  %r15,%rdi
cmp    $0x7f,%al
cmove  %r15,%rdi
movzbl %al,%esi
cmp    $0x20,%al
cmovb  %r15,%rdi
call   1030 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1171 <printstring+0x61>
mov    %r15,%rdi
cmp    $0x22,%al
je     1140 <printstring+0x30>
mov    %r14,%rdi
jmp    1140 <printstring+0x30>
lea    0xe88(%rip),%rdi
mov    $0x22,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

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

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