#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 */
scalar_t__ readchar(int, unsigned char *, int);
int zhenhua_init(int fd, unsigned long *id, unsigned long *extra) {
  unsigned char c[10];
  int count;
  for (count = 0; count < 5; count++) {
    if (readchar(fd, c + 0, 500))
      return -1;
    if (c[0] == 0xef)
      break;
  }
  if (count == 5) {
    return -1;
  }
  for (count = 1; count < 10; count++) {
    if (readchar(fd, c + count, 500))
      return -1;
  }
  if (c[5] != 0xef)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<zhenhua_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x5,-0x28(%rbp)
jge    1182 <zhenhua_init+0x72>
mov    -0x8(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
je     115b <zhenhua_init+0x4b>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <zhenhua_init+0xfc>
movzbl -0x22(%rbp),%eax
cmp    $0xef,%eax
jne    116f <zhenhua_init+0x5f>
jmp    1182 <zhenhua_init+0x72>
jmp    1174 <zhenhua_init+0x64>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    112a <zhenhua_init+0x1a>
cmpl   $0x5,-0x28(%rbp)
jne    1198 <zhenhua_init+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <zhenhua_init+0xfc>
movl   $0x1,-0x28(%rbp)
cmpl   $0xa,-0x28(%rbp)
jge    11ea <zhenhua_init+0xda>
mov    -0x8(%rbp),%edi
lea    -0x22(%rbp),%rsi
movslq -0x28(%rbp),%rax
add    %rax,%rsi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
je     11d7 <zhenhua_init+0xc7>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <zhenhua_init+0xfc>
jmp    11dc <zhenhua_init+0xcc>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119f <zhenhua_init+0x8f>
movzbl -0x1d(%rbp),%eax
cmp    $0xef,%eax
je     1205 <zhenhua_init+0xf5>
movl   $0xffffffff,-0x4(%rbp)
jmp    120c <zhenhua_init+0xfc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zhenhua_init>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
lea    0xe(%rsp),%rsi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     113a <zhenhua_init+0x2a>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
cmpb   $0xef,0xe(%rsp)
jne    1230 <zhenhua_init+0x120>
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x11(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x12(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x13(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x14(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x15(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x16(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
lea    0x17(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
xor    %ebx,%ebx
cmpb   $0xef,0x13(%rsp)
setne  %bl
neg    %ebx
jmp    1131 <zhenhua_init+0x21>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
cmpb   $0xef,0xe(%rsp)
je     1145 <zhenhua_init+0x35>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
cmpb   $0xef,0xe(%rsp)
je     1145 <zhenhua_init+0x35>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
cmpb   $0xef,0xe(%rsp)
je     1145 <zhenhua_init+0x35>
lea    0xe(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1f4,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    1131 <zhenhua_init+0x21>
cmpb   $0xef,0xe(%rsp)
je     1145 <zhenhua_init+0x35>
jmp    1131 <zhenhua_init+0x21>

LLVM IR (-O0):
define i32 @zhenhua_init(i32 %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca [10 x i8]
%9 = alloca i32
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i32 0, i32* %9
br label %10
10: ; preds = %27, %3
%11 = load i32, i32* %9
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32, i32* %5
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = call i64 @readchar(i32 %14, i8* %16, i32 500)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %4
br label %58
20: ; preds = %13
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 239
br i1 %24, label %25, label %26
25: ; preds = %20
br label %30
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = load i32, i32* %9
%29 = add nsw i32 %28, 1
store i32 %29, i32* %9
br label %10
30: ; preds = %25, %10
%31 = load i32, i32* %9
%32 = icmp eq i32 %31, 5
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 -1, i32* %4
br label %58
34: ; preds = %30
store i32 1, i32* %9
br label %35
35: ; preds = %48, %34
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 10
br i1 %37, label %38, label %51
38: ; preds = %35
%39 = load i32, i32* %5
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = call i64 @readchar(i32 %39, i8* %43, i32 500)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %38
store i32 -1, i32* %4
br label %58
47: ; preds = %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %35
51: ; preds = %35
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 5
%53 = load i8, i8* %52
%54 = zext i8 %53 to i32
%55 = icmp ne i32 %54, 239
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 -1, i32* %4
br label %58
57: ; preds = %51
store i32 0, i32* %4
br label %58
58: ; preds = %57, %56, %46, %33, %19
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
define i32 @zhenhua_init(i32 %0, i64* nocapture readnone %1, i64* nocapture readnone %2) {
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%6 = call i64 @readchar(i32 %0, i8* %5, i32 500)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %75
8: ; preds = %3
%9 = load i8, i8* %5
%10 = icmp eq i8 %9, -17
br i1 %10, label %35, label %11
11: ; preds = %8
%12 = call i64 @readchar(i32 %0, i8* %5, i32 500)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %75
14: ; preds = %11
%15 = load i8, i8* %5
%16 = icmp eq i8 %15, -17
br i1 %16, label %35, label %17
17: ; preds = %14
%18 = call i64 @readchar(i32 %0, i8* %5, i32 500)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %75
20: ; preds = %17
%21 = load i8, i8* %5
%22 = icmp eq i8 %21, -17
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = call i64 @readchar(i32 %0, i8* %5, i32 500)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %75
26: ; preds = %23
%27 = load i8, i8* %5
%28 = icmp eq i8 %27, -17
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = call i64 @readchar(i32 %0, i8* %5, i32 500)
%31 = icmp eq i64 %30, 0
%32 = load i8, i8* %5
%33 = icmp eq i8 %32, -17
%34 = select i1 %31, i1 %33, i1 false
br i1 %34, label %35, label %75
35: ; preds = %29, %26, %20, %14, %8
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 1
%37 = call i64 @readchar(i32 %0, i8* %36, i32 500)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %75
39: ; preds = %35
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 2
%41 = call i64 @readchar(i32 %0, i8* %40, i32 500)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %75
43: ; preds = %39
%44 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 3
%45 = call i64 @readchar(i32 %0, i8* %44, i32 500)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %75
47: ; preds = %43
%48 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 4
%49 = call i64 @readchar(i32 %0, i8* %48, i32 500)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %75
51: ; preds = %47
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 5
%53 = call i64 @readchar(i32 %0, i8* %52, i32 500)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %75
55: ; preds = %51
%56 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 6
%57 = call i64 @readchar(i32 %0, i8* %56, i32 500)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %75
59: ; preds = %55
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 7
%61 = call i64 @readchar(i32 %0, i8* %60, i32 500)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %75
63: ; preds = %59
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 8
%65 = call i64 @readchar(i32 %0, i8* %64, i32 500)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %75
67: ; preds = %63
%68 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 9
%69 = call i64 @readchar(i32 %0, i8* %68, i32 500)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %67
%72 = load i8, i8* %52
%73 = icmp ne i8 %72, -17
%74 = sext i1 %73 to i32
br label %75
75: ; preds = %3, %11, %17, %23, %29, %35, %39, %43, %47, %51, %55, %59, %63, %67, %71
%76 = phi i32 [ %74, %71 ], [ -1, %67 ], [ -1, %63 ], [ -1, %59 ], [ -1, %55 ], [ -1, %51 ], [ -1, %47 ], [ -1, %43 ], [ -1, %39 ], [ -1, %35 ], [ -1, %29 ], [ -1, %23 ], [ -1, %17 ], [ -1, %11 ], [ -1, %3 ]
ret i32 %76
}