#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);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int read(int, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void readshow(int fd) {
  char buf[8];
  int n;
  n = read(fd, buf, 1);
  if (n < 0) {
    perror("read");
    exit(1);
  }
  if (n == 0)
    exit(0);
  switch (buf[0]) {
  case ' ':
    strcpy(buf, "' '");
    break;
  case '\n':
    strcpy(buf, "\\n");
    break;
  case '\r':
    strcpy(buf, "\\r");
    break;
  case '\t':
    strcpy(buf, "\\t");
    break;
  case '\v':
    strcpy(buf, "\\v");
    break;
  default:
    buf[1] = '\0';
    break;
  }
  printf("fd%d: %s\n", fd, buf);
}


x86 assembly (clang, -O0):
<readshow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    118f <readshow+0x3f>
lea    0xee0(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jne    11a0 <readshow+0x50>
xor    %edi,%edi
call   1070 <exit@plt>
movsbl -0xc(%rbp),%eax
add    $0xfffffff7,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x17,%eax
ja     1233 <readshow+0xe3>
mov    -0x18(%rbp),%rax
lea    0xe3f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0xc(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1237 <readshow+0xe7>
lea    -0xc(%rbp),%rdi
lea    0xe7f(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1237 <readshow+0xe7>
lea    -0xc(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1237 <readshow+0xe7>
lea    -0xc(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1237 <readshow+0xe7>
lea    -0xc(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1237 <readshow+0xe7>
movb   $0x0,-0xb(%rbp)
mov    -0x4(%rbp),%esi
lea    -0xc(%rbp),%rdx
lea    0xe30(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readshow>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %eax,%eax
js     11e2 <readshow+0x92>
je     11f8 <readshow+0xa8>
movsbl 0x8(%rsp),%eax
add    $0xfffffff7,%eax
cmp    $0x17,%eax
ja     119f <readshow+0x4f>
lea    0xe7c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xedb(%rip),%rsi
jmp    11bf <readshow+0x6f>
lea    0xed5(%rip),%rsi
jmp    11bf <readshow+0x6f>
movb   $0x0,0x9(%rsp)
jmp    11c9 <readshow+0x79>
lea    0xebc(%rip),%rsi
jmp    11bf <readshow+0x6f>
lea    0xeb6(%rip),%rsi
jmp    11bf <readshow+0x6f>
lea    0xea6(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xea5(%rip),%rdi
lea    0x8(%rsp),%rdx
mov    %ebx,%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe77(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [4 x i8] c"' '\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\v\00"
@.str.6 = [10 x i8] c"fd%d: %s\0A\00"
define void @readshow(i32 %0) {
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%7 = call i32 @read(i32 %5, i8* %6, i32 1)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %13
%19 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %37 [
i32 32, label %22
i32 10, label %25
i32 13, label %28
i32 9, label %31
i32 11, label %34
]
22: ; preds = %18
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %39
25: ; preds = %18
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%27 = call i32 @strcpy(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %39
28: ; preds = %18
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %39
31: ; preds = %18
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %39
34: ; preds = %18
%35 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %39
37: ; preds = %18
%38 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 1
store i8 0, i8* %38
br label %39
39: ; preds = %37, %34, %31, %28, %25, %22
%40 = load i32, i32* %2
%41 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %40, i8* %41)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [4 x i8] c"' '\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [3 x i8] c"\\t\00"
@.str.5 = [3 x i8] c"\\v\00"
@.str.6 = [10 x i8] c"fd%d: %s\0A\00"
define void @readshow(i32 %0) {
%2 = alloca [8 x i8]
%3 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = icmp eq i32 %4, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %9
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
switch i32 %15, label %26 [
i32 32, label %16
i32 10, label %18
i32 13, label %20
i32 9, label %22
i32 11, label %24
]
16: ; preds = %13
%17 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %28
18: ; preds = %13
%19 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %28
20: ; preds = %13
%21 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %28
22: ; preds = %13
%23 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %28
24: ; preds = %13
%25 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %28
26: ; preds = %13
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 1
store i8 0, i8* %27
br label %28
28: ; preds = %26, %24, %22, %20, %18, %16
%29 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %0, i8* %3)
ret void
}