#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*/ __debug(int, char *, char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcpy(char *, char *);
void __debug_buffer(int category, char *buffer_name, void *buffer, int size) {
  char buf[200];
  char *buf_ptr;
  unsigned char c;
  int trunc = 0;
  memset(buf, 0, sizeof buf);
  strcpy(buf, "\"");
  buf_ptr = &buf[1];
  if (size > 40) {
    size = 40;
    trunc = 1;
  }
  for (;;) {
    c = *(unsigned char *)buffer;
    if (!size) {
      strcpy(buf_ptr, trunc ? "\"..." : "\"");
      break;
    }
    if (c >= 32) {
      *buf_ptr = c;
      buf_ptr++;
    } else if (!c) {
      strcpy(buf_ptr, "\\0");
      buf_ptr += 2;
    } else if (c == '\n') {
      strcpy(buf_ptr, "\\n");
      buf_ptr += 2;
    } else if (c == '\t') {
      strcpy(buf_ptr, "\\t");
      buf_ptr += 2;
    } else {
      sprintf(buf_ptr, "\\%02x", c);
      buf_ptr += 3;
    }
    buffer++;
    size--;
  }
  __debug(category, "%s=%s\n", buffer_name, buf);
}


x86 assembly (clang, -O0):
<__debug_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x100(%rbp)
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1040 <memset@plt>
lea    -0xf0(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0xf0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
cmpl   $0x28,-0x1c(%rbp)
jle    11b6 <__debug_buffer+0x76>
movl   $0x28,-0x1c(%rbp)
movl   $0x1,-0x100(%rbp)
jmp    11bb <__debug_buffer+0x7b>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xf9(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11fd <__debug_buffer+0xbd>
mov    -0xf8(%rbp),%rdi
mov    -0x100(%rbp),%ecx
lea    0xe1b(%rip),%rsi
lea    0xe16(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
call   1030 <strcpy@plt>
jmp    1333 <__debug_buffer+0x1f3>
movzbl -0xf9(%rbp),%eax
cmp    $0x20,%eax
jl     1233 <__debug_buffer+0xf3>
mov    -0xf9(%rbp),%cl
mov    -0xf8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xf8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xf8(%rbp)
jmp    1319 <__debug_buffer+0x1d9>
cmpb   $0x0,-0xf9(%rbp)
jne    126a <__debug_buffer+0x12a>
mov    -0xf8(%rbp),%rdi
lea    0xdb9(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xf8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0xf8(%rbp)
jmp    1314 <__debug_buffer+0x1d4>
movzbl -0xf9(%rbp),%eax
cmp    $0xa,%eax
jne    12a4 <__debug_buffer+0x164>
mov    -0xf8(%rbp),%rdi
lea    0xd82(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xf8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0xf8(%rbp)
jmp    130f <__debug_buffer+0x1cf>
movzbl -0xf9(%rbp),%eax
cmp    $0x9,%eax
jne    12de <__debug_buffer+0x19e>
mov    -0xf8(%rbp),%rdi
lea    0xd4b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xf8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0xf8(%rbp)
jmp    130a <__debug_buffer+0x1ca>
mov    -0xf8(%rbp),%rdi
lea    0xd24(%rip),%rsi
movzbl -0xf9(%rbp),%edx
call   1060 <sprintf@plt>
mov    -0xf8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0xf8(%rbp)
jmp    130f <__debug_buffer+0x1cf>
jmp    1314 <__debug_buffer+0x1d4>
jmp    1319 <__debug_buffer+0x1d9>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11bb <__debug_buffer+0x7b>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    -0xf0(%rbp),%rcx
lea    0xcce(%rip),%rsi
call   1050 <__debug@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__debug_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    %rsi,0x8(%rsp)
mov    %edi,0x4(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1040 <memset@plt>
lea    0xe85(%rip),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    0x11(%rsp),%rbx
cmp    $0x29,%r12d
mov    $0x28,%eax
cmovl  %r12d,%eax
test   %eax,%eax
je     1220 <__debug_buffer+0xe0>
mov    %eax,%r14d
xor    %r15d,%r15d
jmp    11c3 <__debug_buffer+0x83>
nopl   0x0(%rax,%rax,1)
mov    %al,(%rbx)
mov    $0x1,%eax
add    %rax,%rbx
add    $0x1,%r15
cmp    %r15d,%r14d
je     1220 <__debug_buffer+0xe0>
movzbl 0x0(%rbp,%r15,1),%eax
cmp    $0x20,%al
jae    11b0 <__debug_buffer+0x70>
cmp    $0xa,%al
je     11f1 <__debug_buffer+0xb1>
cmp    $0x9,%al
je     11e5 <__debug_buffer+0xa5>
test   %al,%al
jne    1207 <__debug_buffer+0xc7>
mov    %rbx,%rdi
lea    0xe24(%rip),%rsi
jmp    11fb <__debug_buffer+0xbb>
mov    %rbx,%rdi
lea    0xe1e(%rip),%rsi
jmp    11fb <__debug_buffer+0xbb>
mov    %rbx,%rdi
lea    0xe0f(%rip),%rsi
call   1030 <strcpy@plt>
mov    $0x2,%eax
jmp    11b7 <__debug_buffer+0x77>
movzbl %al,%edx
mov    %rbx,%rdi
lea    0xdfc(%rip),%rsi
call   1060 <sprintf@plt>
mov    $0x3,%eax
jmp    11b7 <__debug_buffer+0x77>
cmp    $0x29,%r12d
lea    0xdd7(%rip),%rax
cmovge %rax,%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
lea    0xdd5(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    0x4(%rsp),%edi
mov    0x8(%rsp),%rdx
call   1050 <__debug@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\22\00"
@.str.1 = [5 x i8] c"\22...\00"
@.str.2 = [3 x i8] c"\\0\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [6 x i8] c"\\%02x\00"
@.str.6 = [7 x i8] c"%s=%s\0A\00"
define void @__debug_buffer(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [200 x i8]
%10 = alloca i8*
%11 = alloca i8
%12 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %12
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%14 = call i32 @memset(i8* %13, i32 0, i32 200)
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 1
store i8* %17, i8** %10
%18 = load i32, i32* %8
%19 = icmp sgt i32 %18, 40
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 40, i32* %8
store i32 1, i32* %12
br label %21
21: ; preds = %20, %4
br label %22
22: ; preds = %78, %21
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
store i8 %24, i8* %11
%25 = load i32, i32* %8
%26 = icmp ne i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %22
%28 = load i8*, i8** %10
%29 = load i32, i32* %12
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%33 = call i32 @strcpy(i8* %28, i8* %32)
br label %83
34: ; preds = %22
%35 = load i8, i8* %11
%36 = zext i8 %35 to i32
%37 = icmp sge i32 %36, 32
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = load i8, i8* %11
%40 = load i8*, i8** %10
store i8 %39, i8* %40
%41 = load i8*, i8** %10
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %10
br label %78
43: ; preds = %34
%44 = load i8, i8* %11
%45 = icmp ne i8 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %43
%47 = load i8*, i8** %10
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%49 = load i8*, i8** %10
%50 = getelementptr inbounds i8, i8* %49, i64 2
store i8* %50, i8** %10
br label %77
51: ; preds = %43
%52 = load i8, i8* %11
%53 = zext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %60
55: ; preds = %51
%56 = load i8*, i8** %10
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%58 = load i8*, i8** %10
%59 = getelementptr inbounds i8, i8* %58, i64 2
store i8* %59, i8** %10
br label %76
60: ; preds = %51
%61 = load i8, i8* %11
%62 = zext i8 %61 to i32
%63 = icmp eq i32 %62, 9
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = load i8*, i8** %10
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%67 = load i8*, i8** %10
%68 = getelementptr inbounds i8, i8* %67, i64 2
store i8* %68, i8** %10
br label %75
69: ; preds = %60
%70 = load i8*, i8** %10
%71 = load i8, i8* %11
%72 = call i32 @sprintf(i8* %70, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %71)
%73 = load i8*, i8** %10
%74 = getelementptr inbounds i8, i8* %73, i64 3
store i8* %74, i8** %10
br label %75
75: ; preds = %69, %64
br label %76
76: ; preds = %75, %55
br label %77
77: ; preds = %76, %46
br label %78
78: ; preds = %77, %38
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i32 1
store i8* %80, i8** %7
%81 = load i32, i32* %8
%82 = add nsw i32 %81, -1
store i32 %82, i32* %8
br label %22
83: ; preds = %27
%84 = load i32, i32* %5
%85 = load i8*, i8** %6
%86 = getelementptr inbounds [200 x i8], [200 x i8]* %9, i64 0, i64 0
%87 = call i32 @__debug(i32 %84, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %85, i8* %86)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\22\00"
@.str.1 = [5 x i8] c"\22...\00"
@.str.2 = [3 x i8] c"\\0\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [6 x i8] c"\\%02x\00"
@.str.6 = [7 x i8] c"%s=%s\0A\00"
define void @__debug_buffer(i32 %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = alloca [200 x i8]
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 200)
%8 = call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 1
%10 = icmp sgt i32 %3, 40
%11 = select i1 %10, i32 40, i32 %3
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %34, %4
%14 = phi i8* [ %9, %4 ], [ %36, %34 ]
%15 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%16 = call i32 @strcpy(i8* %14, i8* %15)
%17 = call i32 @__debug(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %1, i8* %6)
ret void
18: ; preds = %4, %34
%19 = phi i8* [ %37, %34 ], [ %2, %4 ]
%20 = phi i8* [ %36, %34 ], [ %9, %4 ]
%21 = phi i32 [ %38, %34 ], [ %11, %4 ]
%22 = load i8, i8* %19
%23 = icmp ugt i8 %22, 31
br i1 %23, label %24, label %25
24: ; preds = %18
store i8 %22, i8* %20
br label %34
25: ; preds = %18
switch i8 %22, label %32 [
i8 0, label %26
i8 10, label %28
i8 9, label %30
]
26: ; preds = %25
%27 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %34
28: ; preds = %25
%29 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %34
30: ; preds = %25
%31 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %34
32: ; preds = %25
%33 = call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8 zeroext %22)
br label %34
34: ; preds = %26, %30, %32, %28, %24
%35 = phi i64 [ 2, %26 ], [ 2, %30 ], [ 3, %32 ], [ 2, %28 ], [ 1, %24 ]
%36 = getelementptr inbounds i8, i8* %20, i64 %35
%37 = getelementptr inbounds i8, i8* %19, i64 1
%38 = add nsw i32 %21, -1
%39 = icmp eq i32 %38, 0
br i1 %39, label %13, label %18
}