void echo_stderr(n) int n;
{
  static int need_lf;
  char *s;
  switch (n) {
  case '\r':
    break;
  case -1:
    if (need_lf == 0)
      break;
  case '\n':
    write(2, "\n", 1);
    need_lf = 0;
    break;
  default:
    s = character(n);
    write(2, s, strlen(s));
    need_lf = 1;
    break;
  }
}


x86 assembly (clang, -O0):
<echo_stderr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%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    11b4 <echo_stderr+0x84>
jmp    1171 <echo_stderr+0x41>
jmp    11f2 <echo_stderr+0xc2>
cmpl   $0x0,0x2ebf(%rip)
jne    1188 <echo_stderr+0x58>
jmp    11f2 <echo_stderr+0xc2>
jmp    118d <echo_stderr+0x5d>
mov    $0x2,%edi
lea    0xe67(%rip),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <write@plt>
movl   $0x0,0x2e8d(%rip)
jmp    11f2 <echo_stderr+0xc2>
mov    -0x4(%rbp),%edi
mov    $0x0,%al
call   1050 <character@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
mov    $0x2,%edi
mov    $0x0,%al
call   1030 <write@plt>
movl   $0x1,0x2e4a(%rip)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo_stderr>:
push   %rbx
cmp    $0xd,%edi
je     1191 <echo_stderr+0x61>
cmp    $0xa,%edi
je     1149 <echo_stderr+0x19>
cmp    $0xffffffff,%edi
jne    1165 <echo_stderr+0x35>
cmpb   $0x1,0x2ef5(%rip)
jne    1191 <echo_stderr+0x61>
lea    0xeb0(%rip),%rsi
xor    %ebx,%ebx
mov    $0x2,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
jmp    118b <echo_stderr+0x5b>
xor    %eax,%eax
call   1050 <character@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <write@plt>
mov    $0x1,%bl
mov    %bl,0x2eab(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@echo_stderr.need_lf = internal 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 %13 [
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 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i32, ...)*)(i32 2, 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
13: ; preds = %1
%14 = load i32, i32* %2
%15 = call i32 (i32, ...) bitcast (i32 (...)* @character to i32 (i32, ...)*)(i32 %14)
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %3
%18 = load i8*, i8** %3
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @write to i32 (i32, i8*, i64, ...)*)(i32 2, i8* %18, i64 %20)
store i32 1, i32* @echo_stderr.need_lf
br label %22
22: ; preds = %13, %11, %9, %5
ret void
}

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