#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ char_to_escape(char *, unsigned int);
int /*<<< orphan*/ sgml_fputc(unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ sgml_fputs(char *, int /*<<< orphan*/ *);
void sgml_print_strval(const char *v, FILE *out) {
  char buff[16];
  for (; *v; v++) {
    if (*v < ' ' || *v & 0x80) {
      char_to_escape(buff, (unsigned int)*v);
      sgml_fputs(buff, out);
      continue;
    }
    sgml_fputc((unsigned int)*v, out);
  }
}


x86 assembly (clang, -O0):
<sgml_print_strval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b5 <sgml_print_strval+0x85>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jl     1172 <sgml_print_strval+0x42>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1194 <sgml_print_strval+0x64>
lea    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1050 <char_to_escape@plt>
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <sgml_fputs@plt>
jmp    11a4 <sgml_print_strval+0x74>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1040 <sgml_fputc@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1140 <sgml_print_strval+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sgml_print_strval>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    (%rdi),%al
test   %al,%al
je     118c <sgml_print_strval+0x5c>
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0x1,%rbx
mov    %rsp,%r15
jmp    116e <sgml_print_strval+0x3e>
xchg   %ax,%ax
mov    %r15,%rdi
call   1050 <char_to_escape@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <sgml_fputs@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     118c <sgml_print_strval+0x5c>
movsbl %al,%esi
cmp    $0x20,%sil
jl     1150 <sgml_print_strval+0x20>
mov    %esi,%eax
and    $0x80,%eax
jne    1150 <sgml_print_strval+0x20>
mov    %esi,%edi
mov    %r14,%rsi
call   1040 <sgml_fputc@plt>
jmp    1163 <sgml_print_strval+0x33>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @sgml_print_strval(i8* nocapture %0, i32* %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %2, %20
%8 = phi i8 [ %22, %20 ], [ %5, %2 ]
%9 = phi i8* [ %21, %20 ], [ %0, %2 ]
%10 = sext i8 %8 to i32
%11 = icmp sgt i8 %8, 31
%12 = and i32 %10, 128
%13 = icmp eq i32 %12, 0
%14 = select i1 %11, i1 %13, i1 false
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = call i32 @char_to_escape(i8* %4, i32 %10)
%17 = call i32 @sgml_fputs(i8* %4, i32* %1)
br label %20
18: ; preds = %7
%19 = call i32 @sgml_fputc(i32 %10, i32* %1)
br label %20
20: ; preds = %18, %15
%21 = getelementptr inbounds i8, i8* %9, i64 1
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %7
24: ; preds = %20, %2
ret void
}