#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 /*<<< orphan*/ memset(char *, char, int);
int read(int, char *, int);
unsigned char tyan_lcdm_read_key(int fd) {
  int count = 0;
  char key_str[4];
  memset(key_str, '\0', 4);
  count = read(fd, key_str, 4);
  if ((count == 4) && (key_str[0] == (char)0xF1) &&
      (key_str[1] == (char)0x72) && (key_str[3] == (char)0xF2)) {
    return key_str[2];
  }
  return 0xF4;
}


x86 assembly (clang, -O0):
<tyan_lcdm_read_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x4,-0xc(%rbp)
jne    1192 <tyan_lcdm_read_key+0x72>
movsbl -0x10(%rbp),%eax
cmp    $0xfffffff1,%eax
jne    1192 <tyan_lcdm_read_key+0x72>
movsbl -0xf(%rbp),%eax
cmp    $0x72,%eax
jne    1192 <tyan_lcdm_read_key+0x72>
movsbl -0xd(%rbp),%eax
cmp    $0xfffffff2,%eax
jne    1192 <tyan_lcdm_read_key+0x72>
mov    -0xe(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    1196 <tyan_lcdm_read_key+0x76>
movb   $0xf4,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tyan_lcdm_read_key>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
mov    0x5(%rsp),%cl
xor    $0x72,%cl
mov    0x7(%rsp),%dl
xor    $0xf2,%dl
or     %cl,%dl
mov    0x4(%rsp),%cl
xor    $0xf1,%cl
or     %cl,%dl
movzbl 0x6(%rsp),%ecx
mov    $0xf4,%edx
cmovne %edx,%ecx
cmp    $0x4,%eax
cmovne %edx,%ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define zeroext i8 @tyan_lcdm_read_key(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x i8]
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i8 signext 0, i32 4)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 4)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %31
13: ; preds = %1
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, -15
br i1 %17, label %18, label %31
18: ; preds = %13
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 114
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, -14
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%30 = load i8, i8* %29
store i8 %30, i8* %2
br label %32
31: ; preds = %23, %18, %13, %1
store i8 -12, i8* %2
br label %32
32: ; preds = %31, %28
%33 = load i8, i8* %2
ret i8 %33
}

LLVM IR (-O2):
define zeroext i8 @tyan_lcdm_read_key(i32 %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i8 signext 0, i32 4)
%5 = call i32 @read(i32 %0, i8* %3, i32 4)
%6 = icmp eq i32 %5, 4
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, -15
%9 = select i1 %6, i1 %8, i1 false
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 114
%13 = select i1 %9, i1 %12, i1 false
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, -14
%17 = select i1 %13, i1 %16, i1 false
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%19 = load i8, i8* %18
%20 = select i1 %17, i8 %19, i8 -12
ret i8 %20
}