#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ isprint(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ putchar(int);
void writeChar(int curmode, unsigned int value) {
  if (curmode == 0 || curmode == 2) {
    int ch = (value >> 9) & 0xFF;
    if (ch != 10 && !isprint(ch)) {
      printf("writeChar() called with char %dd, which isn't printable\n", ch);
      exit(0);
    }
    putchar(ch);
  }
  if (curmode != 2) {
    int ch = value & 0xFF;
    if (ch != 10 && !isprint(ch)) {
      printf("writeChar() called with char %dd, which isn't printable\n", ch);
      exit(0);
    }
    putchar(ch);
  }
}


x86 assembly (clang, -O0):
<writeChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1162 <writeChar+0x22>
cmpl   $0x2,-0x4(%rbp)
jne    11a9 <writeChar+0x69>
mov    -0x8(%rbp),%eax
shr    $0x9,%eax
and    $0xff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
je     11a1 <writeChar+0x61>
mov    -0xc(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%eax
jne    11a1 <writeChar+0x61>
mov    -0xc(%rbp),%esi
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
cmpl   $0x2,-0x4(%rbp)
je     11f7 <writeChar+0xb7>
mov    -0x8(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
je     11ef <writeChar+0xaf>
mov    -0x10(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%eax
jne    11ef <writeChar+0xaf>
mov    -0x10(%rbp),%esi
lea    0xe1d(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeChar>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
test   $0xfffffffd,%edi
je     115a <writeChar+0x1a>
cmp    $0x2,%ebp
jne    1182 <writeChar+0x42>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebx,%eax
shr    $0x9,%eax
movzbl %al,%r14d
cmp    $0xa,%r14d
je     1175 <writeChar+0x35>
mov    %r14d,%edi
call   1050 <isprint@plt>
test   %eax,%eax
je     11ab <writeChar+0x6b>
mov    %r14d,%edi
call   1030 <putchar@plt>
cmp    $0x2,%ebp
je     1155 <writeChar+0x15>
movzbl %bl,%ebx
cmp    $0xa,%ebx
je     1195 <writeChar+0x55>
mov    %ebx,%edi
call   1050 <isprint@plt>
test   %eax,%eax
je     11a0 <writeChar+0x60>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <putchar@plt>
lea    0xe59(%rip),%rdi
mov    %ebx,%esi
jmp    11b5 <writeChar+0x75>
lea    0xe4e(%rip),%rdi
mov    %r14d,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [57 x i8] c"writeChar() called with char %dd, which isn't printable\0A\00"
define void @writeChar(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %29
12: ; preds = %9, %2
%13 = load i32, i32* %4
%14 = lshr i32 %13, 9
%15 = and i32 %14, 255
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 10
br i1 %17, label %18, label %26
18: ; preds = %12
%19 = load i32, i32* %5
%20 = call i32 @isprint(i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18, %12
%27 = load i32, i32* %5
%28 = call i32 @putchar(i32 %27)
br label %29
29: ; preds = %26, %9
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 2
br i1 %31, label %32, label %48
32: ; preds = %29
%33 = load i32, i32* %4
%34 = and i32 %33, 255
store i32 %34, i32* %6
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %45
37: ; preds = %32
%38 = load i32, i32* %6
%39 = call i32 @isprint(i32 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i32, i32* %6
%43 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = call i32 @exit(i32 0)
unreachable
45: ; preds = %37, %32
%46 = load i32, i32* %6
%47 = call i32 @putchar(i32 %46)
br label %48
48: ; preds = %45, %29
ret void
}

LLVM IR (-O2):
@.str = [57 x i8] c"writeChar() called with char %dd, which isn't printable\0A\00"
define void @writeChar(i32 %0, i32 %1) {
%3 = and i32 %0, -3
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = lshr i32 %1, 9
%7 = and i32 %6, 255
%8 = icmp eq i32 %7, 10
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = tail call i32 @isprint(i32 %7)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %7)
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %9, %5
%16 = tail call i32 @putchar(i32 %7)
br label %17
17: ; preds = %2, %15
%18 = icmp eq i32 %0, 2
br i1 %18, label %30, label %19
19: ; preds = %17
%20 = and i32 %1, 255
%21 = icmp eq i32 %20, 10
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = tail call i32 @isprint(i32 %20)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %20)
%27 = tail call i32 @exit(i32 0)
unreachable
28: ; preds = %22, %19
%29 = tail call i32 @putchar(i32 %20)
br label %30
30: ; preds = %28, %17
ret void
}