#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
void _testbench_print_error(int stream, uint32_t level) {
  bool written = false;
  char buf;
  while (read(stream, &buf, 1) > 0) {
    if (!written) {
      fprintf(stderr, "\n");
      for (int d = 0; d < level; ++d) {
        fprintf(stderr, "  ");
      }
    }
    fprintf(stderr, "%c", buf);
    if (buf == '\n') {
      for (uint32_t d = 0; d < level; ++d) {
        fprintf(stderr, "  ");
      }
    }
    written = true;
  }
  if (written) {
    fprintf(stderr, "\n");
  }
}


x86 assembly (clang, -O0):
<_testbench_print_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x0,%rax
jle    121f <_testbench_print_error+0xff>
cmpl   $0x0,-0xc(%rbp)
jne    11ae <_testbench_print_error+0x8e>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a9 <_testbench_print_error+0x89>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1178 <_testbench_print_error+0x58>
jmp    11ae <_testbench_print_error+0x8e>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
movsbl -0xd(%rbp),%edx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1213 <_testbench_print_error+0xf3>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120e <_testbench_print_error+0xee>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11dd <_testbench_print_error+0xbd>
jmp    1213 <_testbench_print_error+0xf3>
movl   $0x1,-0xc(%rbp)
jmp    1135 <_testbench_print_error+0x15>
cmpl   $0x0,-0xc(%rbp)
je     1240 <_testbench_print_error+0x120>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_testbench_print_error>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %edi,%r12d
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jle    1203 <_testbench_print_error+0xe3>
mov    0x2e90(%rip),%r14
mov    (%r14),%edi
lea    0xea6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
test   %r13d,%r13d
jle    1182 <_testbench_print_error+0x62>
lea    0xe95(%rip),%rbp
mov    %r13d,%ebx
mov    (%r14),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    1170 <_testbench_print_error+0x50>
lea    0x7(%rsp),%r15
lea    0xe74(%rip),%rbp
jmp    11a5 <_testbench_print_error+0x85>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jle    11e4 <_testbench_print_error+0xc4>
mov    (%r14),%edi
movsbl 0x7(%rsp),%ebx
lea    0xe51(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0xa,%ebx
jne    1190 <_testbench_print_error+0x70>
test   %r13d,%r13d
jle    1190 <_testbench_print_error+0x70>
mov    %r13d,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0xffffffff,%ebx
jne    11d0 <_testbench_print_error+0xb0>
jmp    1190 <_testbench_print_error+0x70>
mov    (%r14),%edi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [3 x i8] c"%c\00"
define void @_testbench_print_error(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %50, %2
%10 = load i32, i32* %3
%11 = call i64 @read(i32 %10, i8* %6, i32 1)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %51
13: ; preds = %9
%14 = load i32, i32* %5
%15 = icmp ne i32 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %19
19: ; preds = %26, %16
%20 = load i32, i32* %7
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %23
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %19
29: ; preds = %19
br label %30
30: ; preds = %29, %13
%31 = load i32, i32* @stderr
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i8, i8* %6
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %50
38: ; preds = %30
store i32 0, i32* %8
br label %39
39: ; preds = %46, %38
%40 = load i32, i32* %8
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %49
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %46
46: ; preds = %43
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %39
49: ; preds = %39
br label %50
50: ; preds = %49, %30
store i32 1, i32* %5
br label %9
51: ; preds = %9
%52 = load i32, i32* %5
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %57
57: ; preds = %54, %51
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [2 x i8] c"\0A\00"
@.str.1 = [3 x i8] c" \00"
@.str.2 = [3 x i8] c"%c\00"
define void @_testbench_print_error(i32 %0, i32 %1) {
%3 = alloca i8
%4 = call i64 @read(i32 %0, i8* %3, i32 1)
%5 = icmp sgt i64 %4, 0
br i1 %5, label %6, label %37
6: ; preds = %2
%7 = icmp sgt i32 %1, 0
%8 = icmp slt i32 %1, 1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br i1 %7, label %11, label %17
11: ; preds = %6, %11
%12 = phi i32 [ %15, %11 ], [ 0, %6 ]
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = add nuw nsw i32 %12, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %17, label %11
17: ; preds = %11, %6
br label %18
18: ; preds = %17, %31
%19 = load i32, i32* @stderr
%20 = load i8, i8* %3
%21 = sext i8 %20 to i32
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp ne i8 %20, 10
%24 = or i1 %23, %8
br i1 %24, label %31, label %25
25: ; preds = %18, %25
%26 = phi i32 [ %29, %25 ], [ 0, %18 ]
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = add nuw nsw i32 %26, 1
%30 = icmp eq i32 %29, %1
br i1 %30, label %31, label %25
31: ; preds = %25, %18
%32 = call i64 @read(i32 %0, i8* %3, i32 1)
%33 = icmp sgt i64 %32, 0
br i1 %33, label %18, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %2, %34
ret void
}