#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void fputs2(FILE *out, char *buf, size_t n) {
  int count;
  for (count = 0; n-- > 0; count++) {
    if (buf[count] < 32)
      fprintf(out, "\\x%02x", (int)buf[count]);
    else
      fputc(buf[count], out);
  }
}


x86 assembly (clang, -O0):
<fputs2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
jbe    11b4 <fputs2+0x94>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jge    118a <fputs2+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe80(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11a1 <fputs2+0x81>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    11a6 <fputs2+0x86>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <fputs2+0x1b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fputs2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdx,%rdx
je     117a <fputs2+0x5a>
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xec0(%rip),%r12
jmp    1163 <fputs2+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %edx,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
je     117a <fputs2+0x5a>
movsbl (%r14,%rbx,1),%edx
cmp    $0x1f,%edx
jg     1150 <fputs2+0x30>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <fprintf@plt>
jmp    115a <fputs2+0x3a>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"\\x%02x\00"
define void @fputs2(i32* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %20, label %5
5: ; preds = %3, %17
%6 = phi i64 [ %18, %17 ], [ 0, %3 ]
%7 = phi i64 [ %8, %17 ], [ %2, %3 ]
%8 = add i64 %7, -1
%9 = getelementptr inbounds i8, i8* %1, i64 %6
%10 = load i8, i8* %9
%11 = icmp slt i8 %10, 32
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = sext i8 %10 to i32
%14 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %17
15: ; preds = %5
%16 = tail call i32 @fputc(i8 signext %10, i32* %0)
br label %17
17: ; preds = %12, %15
%18 = add nuw i64 %6, 1
%19 = icmp eq i64 %8, 0
br i1 %19, label %20, label %5
20: ; preds = %17, %3
ret void
}