#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*/ STDERR_FILENO;
char *character(int);
int strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
void echo_stderr(int n) {
  static int need_lf;
  char *s;
  switch (n) {
  case '\r':
    break;
  case -1:
    if (need_lf == 0)
      break;
  case '\n':
    write(STDERR_FILENO, "\n", 1);
    need_lf = 0;
    break;
  default:
    s = character(n);
    write(STDERR_FILENO, s, strlen(s));
    need_lf = 1;
    break;
  }
}


x86 assembly (clang, -O0):
<echo_stderr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1176 <echo_stderr+0x46>
jmp    114f <echo_stderr+0x1f>
mov    -0x14(%rbp),%eax
sub    $0xa,%eax
je     118d <echo_stderr+0x5d>
jmp    1160 <echo_stderr+0x30>
mov    -0x14(%rbp),%eax
sub    $0xd,%eax
jne    11b6 <echo_stderr+0x86>
jmp    1171 <echo_stderr+0x41>
jmp    11f7 <echo_stderr+0xc7>
cmpl   $0x0,0x2ebf(%rip)
jne    1188 <echo_stderr+0x58>
jmp    11f7 <echo_stderr+0xc7>
jmp    118d <echo_stderr+0x5d>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movl   $0x0,0x2e8b(%rip)
jmp    11f7 <echo_stderr+0xc7>
mov    -0x4(%rbp),%edi
call   1050 <character@plt>
mov    %rax,-0x10(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
movl   $0x1,0x2e45(%rip)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo_stderr>:
push   %rbp
push   %rbx
push   %rax
cmp    $0xd,%edi
je     1196 <echo_stderr+0x66>
cmp    $0xa,%edi
je     114b <echo_stderr+0x1b>
cmp    $0xffffffff,%edi
jne    1169 <echo_stderr+0x39>
cmpb   $0x1,0x2ef3(%rip)
jne    1196 <echo_stderr+0x66>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %eax,%eax
jmp    1190 <echo_stderr+0x60>
call   1050 <character@plt>
mov    %rax,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    $0x1,%al
mov    %al,0x2ea6(%rip)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@echo_stderr.need_lf = internal global i32 0
@STDERR_FILENO = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @echo_stderr(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* %2
switch i32 %4, label %14 [
i32 13, label %5
i32 -1, label %6
i32 10, label %11
]
5: ; preds = %1
br label %22
6: ; preds = %1
%7 = load i32, i32* @echo_stderr.need_lf
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
br label %22
10: ; preds = %6
br label %11
11: ; preds = %1, %10
%12 = load i32, i32* @STDERR_FILENO
%13 = call i32 @write(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 0, i32* @echo_stderr.need_lf
br label %22
14: ; preds = %1
%15 = load i32, i32* %2
%16 = call i8* @character(i32 %15)
store i8* %16, i8** %3
%17 = load i32, i32* @STDERR_FILENO
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
store i32 1, i32* @echo_stderr.need_lf
br label %22
22: ; preds = %14, %11, %9, %5
ret void
}

LLVM IR (-O2):
@echo_stderr.need_lf = internal unnamed_addr global i1 false
@STDERR_FILENO = global i32 0
@.str = [2 x i8] c"\0A\00"
define void @echo_stderr(i32 %0) {
switch i32 %0, label %7 [
i32 13, label %14
i32 -1, label %2
i32 10, label %4
]
2: ; preds = %1
%3 = load i1, i1* @echo_stderr.need_lf
br i1 %3, label %4, label %14
4: ; preds = %2, %1
%5 = load i32, i32* @STDERR_FILENO
%6 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
br label %12
7: ; preds = %1
%8 = tail call i8* @character(i32 %0)
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i32 @strlen(i8* %8)
%11 = tail call i32 @write(i32 %9, i8* %8, i32 %10)
br label %12
12: ; preds = %4, %7
%13 = phi i1 [ true, %7 ], [ false, %4 ]
store i1 %13, i1* @echo_stderr.need_lf
br label %14
14: ; preds = %12, %2, %1
ret void
}