#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*/ fflush(int /*<<< orphan*/ *);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ show_warning(char *);
int ask(char *req, char *ans) {
  char buff[1280 + 3];
  int nbytes;
  printf("req: %s\n", req);
  fflush(NULL);
  nbytes = read(0, buff, 1280 + 3);
  if (nbytes < 0) {
    show_warning("Bad result from read");
    return -1;
  }
  if (memcmp(buff, "ok ", 3))
    return -1;
  buff[nbytes - 1] = '\000';
  memcpy(ans, &buff[3], nbytes - 3);
  return 0;
}


x86 assembly (clang, -O0):
<ask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x530,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
lea    -0x520(%rbp),%rsi
xor    %edi,%edi
mov    $0x503,%edx
call   1040 <read@plt>
mov    %eax,-0x524(%rbp)
cmpl   $0x0,-0x524(%rbp)
jge    11ca <ask+0x6a>
lea    0xe50(%rip),%rdi
call   1060 <show_warning@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <ask+0xcf>
lea    -0x520(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x3,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11f8 <ask+0x98>
movl   $0xffffffff,-0x4(%rbp)
jmp    122f <ask+0xcf>
mov    -0x524(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x520(%rbp,%rax,1)
mov    -0x18(%rbp),%rdi
lea    -0x520(%rbp),%rsi
add    $0x3,%rsi
mov    -0x524(%rbp),%edx
sub    $0x3,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x530,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask>:
push   %rbp
push   %r14
push   %rbx
sub    $0x510,%rsp
mov    %rsi,%r14
mov    %rdi,%rsi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <fflush@plt>
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x503,%edx
call   1040 <read@plt>
test   %eax,%eax
js     11db <ask+0x7b>
mov    %eax,%ebp
lea    0xe7e(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1050 <memcmp@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    11ec <ask+0x8c>
movslq %ebp,%rax
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x3(%rsp),%rsi
add    $0xfffffffd,%ebp
mov    %r14,%rdi
mov    %ebp,%edx
call   1070 <memcpy@plt>
xor    %eax,%eax
jmp    11ec <ask+0x8c>
lea    0xe27(%rip),%rdi
call   1060 <show_warning@plt>
mov    $0xffffffff,%eax
add    $0x510,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"req: %s\0A\00"
@.str.1 = [21 x i8] c"Bad result from read\00"
@.str.2 = [4 x i8] c"ok \00"
define i32 @ask(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1283 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 @fflush(i32* null)
%11 = getelementptr inbounds [1283 x i8], [1283 x i8]* %6, i64 0, i64 0
%12 = call i32 @read(i32 0, i8* %11, i32 1283)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 @show_warning(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %32
17: ; preds = %2
%18 = getelementptr inbounds [1283 x i8], [1283 x i8]* %6, i64 0, i64 0
%19 = call i64 @memcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %3
br label %32
22: ; preds = %17
%23 = load i32, i32* %7
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1283 x i8], [1283 x i8]* %6, i64 0, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %5
%28 = getelementptr inbounds [1283 x i8], [1283 x i8]* %6, i64 0, i64 3
%29 = load i32, i32* %7
%30 = sub nsw i32 %29, 3
%31 = call i32 @memcpy(i8* %27, i8* %28, i32 %30)
store i32 0, i32* %3
br label %32
32: ; preds = %22, %21, %15
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@.str = [9 x i8] c"req: %s\0A\00"
@.str.1 = [21 x i8] c"Bad result from read\00"
@.str.2 = [4 x i8] c"ok \00"
define i32 @ask(i8* %0, i8* %1) {
%3 = alloca [1283 x i8]
%4 = getelementptr inbounds [1283 x i8], [1283 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = tail call i32 @fflush(i32* null)
%7 = call i32 @read(i32 0, i8* %4, i32 1283)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @show_warning(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %21
11: ; preds = %2
%12 = call i64 @memcmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = add nsw i32 %7, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1283 x i8], [1283 x i8]* %3, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [1283 x i8], [1283 x i8]* %3, i64 0, i64 3
%19 = add nsw i32 %7, -3
%20 = call i32 @memcpy(i8* %1, i8* %18, i32 %19)
br label %21
21: ; preds = %11, %14, %9
%22 = phi i32 [ -1, %9 ], [ 0, %14 ], [ -1, %11 ]
ret i32 %22
}