#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 read(int const, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
char *get_answer(const int fd) {
  static char buf[8192];
  int len;
  len = read(fd, buf, 8192);
  if (len <= 0) {
    return ((char *)NULL);
  }
  while (len > 1 && (buf[len - 1] == '\n' || buf[len - 1] == '\r')) {
    buf[len - 1] = '\0';
    len--;
  }
  if (!strncmp(buf, "OK ", 3)) {
    return (buf + 3);
  } else if (len > 2 && !strcmp(buf + len - 2, "OK")) {
    *(buf + len - 2) = '\0';
    return (buf);
  } else if (len == 2 && !strcmp(buf + len - 2, "OK")) {
    return (buf);
  }
  return ((char *)NULL);
}


x86 assembly (clang, -O0):
<get_answer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    0x2f0b(%rip),%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jg     1169 <get_answer+0x39>
movq   $0x0,-0x8(%rbp)
jmp    12cd <get_answer+0x19d>
jmp    116e <get_answer+0x3e>
xor    %eax,%eax
cmpl   $0x1,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jle    11c2 <get_answer+0x92>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ec3(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x12(%rbp)
je     11bc <get_answer+0x8c>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2ea1(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11d2 <get_answer+0xa2>
jmp    11f4 <get_answer+0xc4>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e6e(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    116e <get_answer+0x3e>
lea    0x2e55(%rip),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1229 <get_answer+0xf9>
lea    0x2e34(%rip),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    12cd <get_answer+0x19d>
cmpl   $0x2,-0x10(%rbp)
jle    127a <get_answer+0x14a>
movslq -0x10(%rbp),%rax
lea    0x2e12(%rip),%rdi
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xdb8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    127a <get_answer+0x14a>
movslq -0x10(%rbp),%rcx
lea    0x2deb(%rip),%rax
movb   $0x0,-0x2(%rax,%rcx,1)
lea    0x2ddf(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12cd <get_answer+0x19d>
cmpl   $0x2,-0x10(%rbp)
jne    12bb <get_answer+0x18b>
movslq -0x10(%rbp),%rax
lea    0x2dc1(%rip),%rdi
add    %rax,%rdi
add    $0xfffffffffffffffe,%rdi
lea    0xd67(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12bb <get_answer+0x18b>
lea    0x2d9e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12cd <get_answer+0x19d>
jmp    12c0 <get_answer+0x190>
jmp    12c5 <get_answer+0x195>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_answer>:
push   %r15
push   %r14
push   %rbx
lea    0x2f14(%rip),%r14
mov    %r14,%rsi
mov    $0x2000,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1219 <get_answer+0xe9>
cmp    $0x1,%eax
jne    117b <get_answer+0x4b>
lea    0x2ef3(%rip),%rdi
lea    0xe9c(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    1219 <get_answer+0xe9>
jmp    11f4 <get_answer+0xc4>
mov    %eax,%eax
jmp    118e <get_answer+0x5e>
nop
movb   $0x0,(%rcx,%r14,1)
cmp    $0x2,%rax
mov    %rbx,%rax
jbe    11a6 <get_answer+0x76>
lea    -0x1(%rax),%rbx
mov    %ebx,%ecx
movzbl (%rcx,%r14,1),%edx
cmp    $0xd,%dl
je     1180 <get_answer+0x50>
cmp    $0xa,%dl
je     1180 <get_answer+0x50>
mov    %rax,%rbx
lea    0x2ea3(%rip),%r15
lea    0xe4c(%rip),%rsi
mov    %r15,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11f4 <get_answer+0xc4>
cmp    $0x3,%ebx
jl     11fd <get_answer+0xcd>
mov    %ebx,%eax
lea    0x2e7d(%rip),%r15
lea    (%rax,%r15,1),%r14
add    $0xfffffffffffffffe,%r14
lea    0xe22(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1219 <get_answer+0xe9>
movb   $0x0,(%r14)
jmp    121c <get_answer+0xec>
lea    0x2e58(%rip),%r15
jmp    121c <get_answer+0xec>
cmp    $0x2,%ebx
jne    1219 <get_answer+0xe9>
mov    $0x4b4f,%eax
xor    0x2e43(%rip),%eax
movzbl 0x2e3e(%rip),%ecx
or     %ax,%cx
je     121c <get_answer+0xec>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_answer.buf = internal global [8192 x i8] zeroinitializer
@.str = [4 x i8] c"OK \00"
@.str.1 = [3 x i8] c"OK\00"
define i8* @get_answer(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @read(i32 %5, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i32 8192)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %74
10: ; preds = %1
br label %11
11: ; preds = %34, %10
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %32
14: ; preds = %11
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %30, label %22
22: ; preds = %14
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 13
br label %30
30: ; preds = %22, %14
%31 = phi i1 [ true, %14 ], [ %29, %22 ]
br label %32
32: ; preds = %30, %11
%33 = phi i1 [ false, %11 ], [ %31, %30 ]
br i1 %33, label %34, label %41
34: ; preds = %32
%35 = load i32, i32* %4
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 %37
store i8 0, i8* %38
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %11
41: ; preds = %32
%42 = call i32 @strncmp(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %41
store i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 3), i8** %2
br label %74
45: ; preds = %41
%46 = load i32, i32* %4
%47 = icmp sgt i32 %46, 2
br i1 %47, label %48, label %60
48: ; preds = %45
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i64 %50
%52 = getelementptr inbounds i8, i8* %51, i64 -2
%53 = call i32 @strcmp(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%54 = icmp ne i32 %53, 0
br i1 %54, label %60, label %55
55: ; preds = %48
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i64 %57
%59 = getelementptr inbounds i8, i8* %58, i64 -2
store i8 0, i8* %59
store i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8** %2
br label %74
60: ; preds = %48, %45
%61 = load i32, i32* %4
%62 = icmp eq i32 %61, 2
br i1 %62, label %63, label %71
63: ; preds = %60
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i64 %65
%67 = getelementptr inbounds i8, i8* %66, i64 -2
%68 = call i32 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%69 = icmp ne i32 %68, 0
br i1 %69, label %71, label %70
70: ; preds = %63
store i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8** %2
br label %74
71: ; preds = %63, %60
br label %72
72: ; preds = %71
br label %73
73: ; preds = %72
store i8* null, i8** %2
br label %74
74: ; preds = %73, %70, %55, %44, %9
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@get_answer.buf = internal global [8192 x i8] zeroinitializer
@.str = [4 x i8] c"OK \00"
@.str.1 = [3 x i8] c"OK\00"
define i8* @get_answer(i32 %0) {
%2 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i32 8192)
%3 = icmp slt i32 %2, 1
br i1 %3, label %39, label %4
4: ; preds = %1
%5 = icmp eq i32 %2, 1
br i1 %5, label %21, label %6
6: ; preds = %4
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %14
%9 = phi i64 [ %7, %6 ], [ %10, %14 ]
%10 = add nsw i64 %9, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 %11
%13 = load i8, i8* %12
switch i8 %13, label %16 [
i8 10, label %14
i8 13, label %14
]
14: ; preds = %8, %8
store i8 0, i8* %12
%15 = icmp ugt i64 %9, 2
br i1 %15, label %8, label %16
16: ; preds = %14, %8
%17 = phi i64 [ %10, %14 ], [ %9, %8 ]
%18 = trunc i64 %17 to i32
%19 = tail call i32 @strncmp(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %39, label %24
21: ; preds = %4
%22 = tail call i32 @strncmp(i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%23 = icmp eq i32 %22, 0
br i1 %23, label %39, label %38
24: ; preds = %16
%25 = icmp sgt i32 %18, 2
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = and i64 %17, 4294967295
%28 = getelementptr inbounds [8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 %27
%29 = getelementptr inbounds i8, i8* %28, i64 -2
%30 = tail call i32 @strcmp(i8* %29, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %26
store i8 0, i8* %29
br label %39
33: ; preds = %24
%34 = icmp eq i32 %18, 2
br i1 %34, label %35, label %38
35: ; preds = %33
%36 = tail call i32 @bcmp(i8* dereferenceable(3) getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64 3)
%37 = icmp eq i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %21, %26, %35, %33
br label %39
39: ; preds = %21, %35, %16, %1, %38, %32
%40 = phi i8* [ null, %38 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), %32 ], [ null, %1 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 3), %16 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 0), %35 ], [ getelementptr inbounds ([8192 x i8], [8192 x i8]* @get_answer.buf, i64 0, i64 3), %21 ]
ret i8* %40
}