#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 */
scalar_t__ debug_dprintf(int, char *, ...);
int debug_output_str(int fd, const char *prefix, const char *str) {
  if (str) {
    char *ptr = (char *)str;
    if (prefix) {
      if (debug_dprintf(fd, "%s", prefix) < 0) {
        do {
          ;
        } while (0);
        return (-1);
      }
    }
    while (*ptr != '\0') {
      if (*ptr == '\n') {
        if (debug_dprintf(fd, "%c", *ptr++) < 0) {
          do {
            ;
          } while (0);
          return (-1);
        }
        if (prefix) {
          if (debug_dprintf(fd, "%s", prefix) < 0) {
            do {
              ;
            } while (0);
            return (-1);
          }
        }
      } else {
        if (debug_dprintf(fd, "%c", *ptr++) < 0) {
          do {
            ;
          } while (0);
          return (-1);
        }
      }
    }
    if (debug_dprintf(fd, "\n") < 0) {
      do {
        ;
      } while (0);
      return (-1);
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<debug_output_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12b0 <debug_output_str+0x1a0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117b <debug_output_str+0x6b>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1030 <debug_dprintf@plt>
cmp    $0x0,%rax
jge    1176 <debug_output_str+0x66>
jmp    1165 <debug_output_str+0x55>
jmp    116a <debug_output_str+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <debug_output_str+0x1a7>
jmp    117b <debug_output_str+0x6b>
jmp    1180 <debug_output_str+0x70>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     127a <debug_output_str+0x16a>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    122d <debug_output_str+0x11d>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <debug_dprintf@plt>
cmp    $0x0,%rax
jge    11e3 <debug_output_str+0xd3>
jmp    11d2 <debug_output_str+0xc2>
jmp    11d7 <debug_output_str+0xc7>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <debug_output_str+0x1a7>
cmpq   $0x0,-0x10(%rbp)
je     1228 <debug_output_str+0x118>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rdx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1030 <debug_dprintf@plt>
cmp    $0x0,%rax
jge    1223 <debug_output_str+0x113>
jmp    1212 <debug_output_str+0x102>
jmp    1217 <debug_output_str+0x107>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <debug_output_str+0x1a7>
jmp    1228 <debug_output_str+0x118>
jmp    1275 <debug_output_str+0x165>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edx
lea    0xdba(%rip),%rsi
mov    $0x0,%al
call   1030 <debug_dprintf@plt>
cmp    $0x0,%rax
jge    1270 <debug_output_str+0x160>
jmp    125f <debug_output_str+0x14f>
jmp    1264 <debug_output_str+0x154>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <debug_output_str+0x1a7>
jmp    1275 <debug_output_str+0x165>
jmp    1180 <debug_output_str+0x70>
mov    -0x8(%rbp),%edi
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1030 <debug_dprintf@plt>
cmp    $0x0,%rax
jge    12ab <debug_output_str+0x19b>
jmp    129a <debug_output_str+0x18a>
jmp    129f <debug_output_str+0x18f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b7 <debug_output_str+0x1a7>
jmp    12b0 <debug_output_str+0x1a0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<debug_output_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11e9 <debug_output_str+0xd9>
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r13d
test   %rsi,%rsi
je     114f <debug_output_str+0x3f>
lea    0xec7(%rip),%rsi
mov    %r13d,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <debug_dprintf@plt>
test   %rax,%rax
js     11ed <debug_output_str+0xdd>
lea    0xead(%rip),%r15
lea    0xea3(%rip),%r12
mov    $0xffffffff,%ebp
jmp    1174 <debug_output_str+0x64>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
movsbl (%rbx),%edx
cmp    $0xa,%edx
je     11a0 <debug_output_str+0x90>
test   %dl,%dl
je     11d3 <debug_output_str+0xc3>
mov    %r13d,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <debug_dprintf@plt>
test   %rax,%rax
jns    1170 <debug_output_str+0x60>
jmp    11ed <debug_output_str+0xdd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0xa,%edx
xor    %eax,%eax
call   1030 <debug_dprintf@plt>
test   %rax,%rax
js     11f2 <debug_output_str+0xe2>
test   %r14,%r14
je     1170 <debug_output_str+0x60>
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <debug_dprintf@plt>
test   %rax,%rax
jns    1170 <debug_output_str+0x60>
jmp    11f2 <debug_output_str+0xe2>
lea    0xe2c(%rip),%rsi
mov    %r13d,%edi
xor    %eax,%eax
call   1030 <debug_dprintf@plt>
test   %rax,%rax
js     11ed <debug_output_str+0xdd>
xor    %ebp,%ebp
jmp    11f2 <debug_output_str+0xe2>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @debug_output_str(i32 %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %2, null
br i1 %4, label %30, label %5
5: ; preds = %3
%6 = icmp eq i8* %1, null
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i64 (i32, i8*, ...) @debug_dprintf(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %31, label %10
10: ; preds = %7, %5
br label %11
11: ; preds = %10, %25
%12 = phi i8* [ %26, %25 ], [ %2, %10 ]
%13 = load i8, i8* %12
switch i8 %13, label %21 [
i8 0, label %27
i8 10, label %14
]
14: ; preds = %11
%15 = tail call i64 (i32, i8*, ...) @debug_dprintf(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 10)
%16 = icmp slt i64 %15, 0
br i1 %16, label %31, label %17
17: ; preds = %14
br i1 %6, label %25, label %18
18: ; preds = %17
%19 = tail call i64 (i32, i8*, ...) @debug_dprintf(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%20 = icmp slt i64 %19, 0
br i1 %20, label %31, label %25
21: ; preds = %11
%22 = sext i8 %13 to i32
%23 = tail call i64 (i32, i8*, ...) @debug_dprintf(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %21, %17, %18
%26 = getelementptr inbounds i8, i8* %12, i64 1
br label %11
27: ; preds = %11
%28 = tail call i64 (i32, i8*, ...) @debug_dprintf(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp sgt i64 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %27, %3
br label %31
31: ; preds = %21, %18, %14, %7, %27, %30
%32 = phi i32 [ -1, %27 ], [ 0, %30 ], [ -1, %7 ], [ -1, %14 ], [ -1, %18 ], [ -1, %21 ]
ret i32 %32
}