#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 ask(char *, char *);
int sscanf(char *, char *, int *);
int req_to_int(char *req, int *res) {
  char ans[128];
  int i;
  i = ask(req, ans);
  if (i != 0)
    return -1;
  i = sscanf(ans, "%d", res);
  if (i != 1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<req_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1030 <ask@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
je     1162 <req_to_int+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <req_to_int+0x7f>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8c(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x1,-0xa4(%rbp)
je     1198 <req_to_int+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    119f <req_to_int+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<req_to_int>:
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%rbx
mov    %rsp,%rsi
call   1030 <ask@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    115c <req_to_int+0x3c>
lea    0xebb(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
call   1040 <sscanf@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
setne  %al
neg    %eax
add    $0x80,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @req_to_int(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [128 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%10 = call i32 @ask(i8* %8, i8* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %22
14: ; preds = %2
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%16 = load i32*, i32** %5
%17 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %3
br label %22
21: ; preds = %14
store i32 0, i32* %3
br label %22
22: ; preds = %21, %20, %13
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @req_to_int(i8* %0, i32* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @ask(i8* %0, i8* %4)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = icmp ne i32 %8, 1
%10 = sext i1 %9 to i32
br label %11
11: ; preds = %7, %2
%12 = phi i32 [ -1, %2 ], [ %10, %7 ]
ret i32 %12
}