#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 */
struct buffer {
  int dummy;
};
typedef int /*<<< orphan*/ str;

/* Variables and functions */
scalar_t__ buffer_append_str(struct buffer *, char *, int);
char get_hexdigit(char);
int encode_nonprint(struct buffer *output, char c) {
  char str[6] = {'\\',
                 'u',
                 '0',
                 '0',
                 get_hexdigit((c & 0xf0) >> 8),
                 get_hexdigit(c & 0xf)};
  if (buffer_append_str(output, str, sizeof(str)) < 0)
    return 1;
  return 1;
}


x86 assembly (clang, -O0):
<encode_nonprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
movb   $0x5c,-0x17(%rbp)
movb   $0x75,-0x16(%rbp)
movb   $0x30,-0x15(%rbp)
movb   $0x30,-0x14(%rbp)
movsbl -0x11(%rbp),%eax
and    $0xf0,%eax
sar    $0x8,%eax
movsbl %al,%edi
call   1040 <get_hexdigit@plt>
mov    %al,-0x13(%rbp)
movsbl -0x11(%rbp),%eax
and    $0xf,%eax
movsbl %al,%edi
call   1040 <get_hexdigit@plt>
mov    %al,-0x12(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x17(%rbp),%rsi
mov    $0x6,%edx
call   1030 <buffer_append_str@plt>
cmp    $0x0,%rax
jge    1193 <encode_nonprint+0x73>
movl   $0x1,-0x4(%rbp)
jmp    119a <encode_nonprint+0x7a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encode_nonprint>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
movl   $0x3030755c,0x2(%rsp)
30
xor    %edi,%edi
call   1040 <get_hexdigit@plt>
mov    %al,0x6(%rsp)
and    $0xf,%ebx
mov    %ebx,%edi
call   1040 <get_hexdigit@plt>
mov    %al,0x7(%rsp)
lea    0x2(%rsp),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1030 <buffer_append_str@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
define i32 @encode_nonprint(%struct.buffer* %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca %struct.buffer*
%5 = alloca i8
%6 = alloca [6 x i8]
store %struct.buffer* %0, %struct.buffer** %4
store i8 %1, i8* %5
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
store i8 92, i8* %7
%8 = getelementptr inbounds i8, i8* %7, i64 1
store i8 117, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 48, i8* %9
%10 = getelementptr inbounds i8, i8* %9, i64 1
store i8 48, i8* %10
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %5
%13 = sext i8 %12 to i32
%14 = and i32 %13, 240
%15 = ashr i32 %14, 8
%16 = trunc i32 %15 to i8
%17 = call signext i8 @get_hexdigit(i8 signext %16)
store i8 %17, i8* %11
%18 = getelementptr inbounds i8, i8* %11, i64 1
%19 = load i8, i8* %5
%20 = sext i8 %19 to i32
%21 = and i32 %20, 15
%22 = trunc i32 %21 to i8
%23 = call signext i8 @get_hexdigit(i8 signext %22)
store i8 %23, i8* %18
%24 = load %struct.buffer*, %struct.buffer** %4
%25 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%26 = call i64 @buffer_append_str(%struct.buffer* %24, i8* %25, i32 6)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %2
store i32 1, i32* %3
br label %30
29: ; preds = %2
store i32 1, i32* %3
br label %30
30: ; preds = %29, %28
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define i32 @encode_nonprint(%struct.buffer* %0, i8 signext %1) {
%3 = alloca [6 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
store i8 92, i8* %4
%5 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 1
store i8 117, i8* %5
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 2
store i8 48, i8* %6
%7 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 3
store i8 48, i8* %7
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 4
%9 = tail call signext i8 @get_hexdigit(i8 signext 0)
store i8 %9, i8* %8
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 5
%11 = and i8 %1, 15
%12 = tail call signext i8 @get_hexdigit(i8 signext %11)
store i8 %12, i8* %10
%13 = call i64 @buffer_append_str(%struct.buffer* %0, i8* %4, i32 6)
ret i32 1
}