#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 atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int bot_response(int *res) {
  char buffer[32];
  bzero(buffer, 32);
  (*res) = read(0, buffer, 32);
  if ((*res) == -1)
    return (-1);
  buffer[(*res) - 1] = '\0';
  if (!strcmp(buffer, "exit") || (*res) == 0)
    return (-2);
  (*res) = atoi(buffer);
  if ((*res) <= 0)
    return (1);
  return (0);
}


x86 assembly (clang, -O0):
<bot_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
call   1050 <bzero@plt>
lea    -0x30(%rbp),%rsi
xor    %edi,%edi
mov    $0x20,%edx
call   1030 <read@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    118b <bot_response+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <bot_response+0xbe>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
je     11c1 <bot_response+0x81>
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11cd <bot_response+0x8d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11fe <bot_response+0xbe>
lea    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11f7 <bot_response+0xb7>
movl   $0x1,-0x4(%rbp)
jmp    11fe <bot_response+0xbe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bot_response>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
call   1040 <bzero@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1030 <read@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     11a3 <bot_response+0x73>
mov    %eax,%ecx
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    $0x74697865,%eax
xor    (%rsp),%eax
movzbl 0x4(%rsp),%esi
xor    %edx,%edx
or     %eax,%esi
setne  %bl
mov    $0xfffffffe,%eax
test   %ecx,%ecx
je     11a8 <bot_response+0x78>
mov    %bl,%dl
test   %edx,%edx
je     11a8 <bot_response+0x78>
mov    %rsp,%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
xor    %eax,%eax
test   %ecx,%ecx
setle  %al
jmp    11a8 <bot_response+0x78>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"exit\00"
define i32 @bot_response(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [32 x i8]
store i32* %0, i32** %3
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 32)
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = call i32 @read(i32 0, i8* %7, i32 32)
%9 = load i32*, i32** %3
store i32 %8, i32* %9
%10 = load i32*, i32** %3
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %37
14: ; preds = %1
%15 = load i32*, i32** %3
%16 = load i32, i32* %15
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %14
%24 = load i32*, i32** %3
%25 = load i32, i32* %24
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23, %14
store i32 -2, i32* %2
br label %37
28: ; preds = %23
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%30 = call i32 @atoi(i8* %29)
%31 = load i32*, i32** %3
store i32 %30, i32* %31
%32 = load i32*, i32** %3
%33 = load i32, i32* %32
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %28
store i32 1, i32* %2
br label %37
36: ; preds = %28
store i32 0, i32* %2
br label %37
37: ; preds = %36, %35, %27, %13
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str = [5 x i8] c"exit\00"
define i32 @bot_response(i32* nocapture %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 32)
%5 = call i32 @read(i32 0, i8* %3, i32 32)
store i32 %5, i32* %0
%6 = icmp eq i32 %5, -1
br i1 %6, label %19, label %7
7: ; preds = %1
%8 = add nsw i32 %5, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @bcmp(i8* dereferenceable(5) %3, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5)
%12 = icmp eq i32 %11, 0
%13 = icmp eq i32 %5, 0
%14 = or i1 %13, %12
br i1 %14, label %19, label %15
15: ; preds = %7
%16 = call i32 @atoi(i8* %3)
store i32 %16, i32* %0
%17 = icmp slt i32 %16, 1
%18 = zext i1 %17 to i32
br label %19
19: ; preds = %15, %7, %1
%20 = phi i32 [ -1, %1 ], [ -2, %7 ], [ %18, %15 ]
ret i32 %20
}