#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 /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ isdigit(char);
scalar_t__ isspace(char);
bool gdi_check_file(FILE *f) {
  char buf[3];
  if (fread(buf, 1, sizeof(buf), f) != sizeof(buf))
    return false;
  return (isdigit(buf[0]) &&
          (isspace(buf[1]) || (isdigit(buf[1]) && isspace(buf[2]))));
}


x86 assembly (clang, -O0):
<gdi_check_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x13(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
cltq
cmp    $0x3,%rax
je     116b <gdi_check_file+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    11e6 <gdi_check_file+0xb6>
movsbl -0x13(%rbp),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x14(%rbp)
je     11db <gdi_check_file+0xab>
movsbl -0x12(%rbp),%edi
call   1050 <isspace@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
jne    11d5 <gdi_check_file+0xa5>
movsbl -0x12(%rbp),%edi
call   1030 <isdigit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x16(%rbp)
je     11cf <gdi_check_file+0x9f>
movsbl -0x11(%rbp),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
mov    %al,-0x14(%rbp)
mov    -0x14(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gdi_check_file>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rcx
lea    0x5(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
xor    %ebx,%ebx
cmp    $0x3,%eax
jne    1199 <gdi_check_file+0x69>
movsbl 0x5(%rsp),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1199 <gdi_check_file+0x69>
movsbl 0x6(%rsp),%ebp
mov    %ebp,%edi
call   1050 <isspace@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1199 <gdi_check_file+0x69>
mov    %ebp,%edi
call   1030 <isdigit@plt>
mov    $0x0,%ebx
test   %rax,%rax
je     1199 <gdi_check_file+0x69>
movsbl 0x7(%rsp),%edi
call   1050 <isspace@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @gdi_check_file(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [3 x i8]
store i32* %0, i32** %3
%5 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%6 = load i32*, i32** %3
%7 = call i32 @fread(i8* %5, i32 1, i32 3, i32* %6)
%8 = sext i32 %7 to i64
%9 = icmp ne i64 %8, 3
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %38
11: ; preds = %1
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%13 = load i8, i8* %12
%14 = call i64 @isdigit(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %11
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %33, label %21
21: ; preds = %16
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 1
%23 = load i8, i8* %22
%24 = call i64 @isdigit(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 2
%28 = load i8, i8* %27
%29 = call i64 @isspace(i8 signext %28)
%30 = icmp ne i64 %29, 0
br label %31
31: ; preds = %26, %21
%32 = phi i1 [ false, %21 ], [ %30, %26 ]
br label %33
33: ; preds = %31, %16
%34 = phi i1 [ true, %16 ], [ %32, %31 ]
br label %35
35: ; preds = %33, %11
%36 = phi i1 [ false, %11 ], [ %34, %33 ]
%37 = zext i1 %36 to i32
store i32 %37, i32* %2
br label %38
38: ; preds = %35, %10
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @gdi_check_file(i32* nocapture %0) {
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%4 = call i32 @fread(i8* %3, i32 1, i32 3, i32* %0)
%5 = icmp eq i32 %4, 3
br i1 %5, label %6, label %24
6: ; preds = %1
%7 = load i8, i8* %3
%8 = tail call i64 @isdigit(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%12 = load i8, i8* %11
%13 = tail call i64 @isspace(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %10
%16 = tail call i64 @isdigit(i8 signext %12)
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
%20 = load i8, i8* %19
%21 = tail call i64 @isspace(i8 signext %20)
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %6, %15, %18, %10, %1
%25 = phi i32 [ 0, %1 ], [ 0, %6 ], [ 1, %10 ], [ 0, %15 ], [ %23, %18 ]
ret i32 %25
}