#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 */
typedef int int8_t;

/* Variables and functions */
scalar_t__ next_is_not_constituent();
int scanf(char *, ...);
int /*<<< orphan*/ skipspaces();
int read_int8(void *dest) {
  skipspaces();
  int x;
  if (scanf("%i", &x) == 1) {
    *(int8_t *)dest = x;
    scanf("i8");
    return next_is_not_constituent() ? 0 : 1;
  } else {
    return 1;
  }
}


x86 assembly (clang, -O0):
<read_int8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <skipspaces@plt>
lea    0xeb6(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1195 <read_int8+0x65>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    $0x0,%al
call   1040 <next_is_not_constituent@plt>
mov    %rax,%rdx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    119c <read_int8+0x6c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int8>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <skipspaces@plt>
lea    0xeba(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
jne    1184 <read_int8+0x54>
mov    0xc(%rsp),%eax
mov    %eax,(%rbx)
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
xor    %eax,%eax
call   1040 <next_is_not_constituent@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"i8\00"
define i32 @read_int8(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 (...) @skipspaces()
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* %4
%10 = load i8*, i8** %3
%11 = bitcast i8* %10 to i32*
store i32 %9, i32* %11
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 (...) @next_is_not_constituent()
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 0, i32 1
store i32 %16, i32* %2
br label %18
17: ; preds = %1
store i32 1, i32* %2
br label %18
18: ; preds = %17, %8
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
@.str.1 = [3 x i8] c"i8\00"
define i32 @read_int8(i8* nocapture writeonly %0) {
%2 = alloca i32
%3 = tail call i32 (...) @skipspaces()
%4 = bitcast i32* %2 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* %2
%9 = bitcast i8* %0 to i32*
store i32 %8, i32* %9
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = call i64 (...) @next_is_not_constituent()
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %1, %7
%15 = phi i32 [ %13, %7 ], [ 1, %1 ]
ret i32 %15
}