#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*/ printf(char *, ...);
char readchar(int);
int response(int fd) {
  char c;
  printf("response: ");
  while ((c = readchar(fd)) > 0) {
    if (c > 48 && c < 122)
      printf("%c", c);
    else
      printf(".");
    if (c == '>') {
      printf("\n");
      return 0;
    }
  }
  printf("\n");
  return 1;
}


x86 assembly (clang, -O0):
<response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <readchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
jle    11bb <response+0x9b>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jle    1181 <response+0x61>
movsbl -0x9(%rbp),%eax
cmp    $0x7a,%eax
jge    1181 <response+0x61>
movsbl -0x9(%rbp),%esi
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118f <response+0x6f>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x9(%rbp),%eax
cmp    $0x3e,%eax
jne    11b6 <response+0x96>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d0 <response+0xb0>
jmp    1139 <response+0x19>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<response>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
lea    0xec3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2e,%r14d
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
call   1040 <readchar@plt>
test   %al,%al
jle    117a <response+0x4a>
mov    %eax,%ebx
lea    -0x31(%rbx),%eax
cmp    $0x49,%al
movzbl %bl,%eax
cmovae %r14d,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
cmp    $0x3e,%bl
jne    1150 <response+0x20>
xor    %ebx,%ebx
jmp    117f <response+0x4f>
mov    $0x1,%ebx
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"response: \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @response(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %31, %1
%7 = load i32, i32* %3
%8 = call signext i8 @readchar(i32 %7)
store i8 %8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %32
11: ; preds = %6
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = icmp sgt i32 %13, 48
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp slt i32 %17, 122
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %25
23: ; preds = %15, %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 62
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %34
31: ; preds = %25
br label %6
32: ; preds = %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %2
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
@.str = [11 x i8] c"response: \00"
define i32 @response(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %6, %1
%4 = tail call signext i8 @readchar(i32 %0)
%5 = icmp sgt i8 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = add nsw i8 %4, -49
%8 = icmp ult i8 %7, 73
%9 = select i1 %8, i8 %4, i8 46
%10 = sext i8 %9 to i32
%11 = tail call i32 @putchar(i32 %10)
%12 = icmp eq i8 %4, 62
br i1 %12, label %13, label %3
13: ; preds = %3, %6
%14 = phi i32 [ 0, %6 ], [ 1, %3 ]
%15 = tail call i32 @putchar(i32 10)
ret i32 %14
}