#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(unsigned char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, unsigned char, unsigned char, unsigned char,
                          unsigned char);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int init_check(int fd) {
  int ret;
  unsigned char Check[] = {0xFB, 0x33, 0x44, 0x55, 0x66, 0xBF};
  unsigned char RECV[10];
  memset(&RECV[0], 10, 0);
  write(fd, &Check[0], 6);
  usleep(1000 * 200);
  read(fd, &RECV[0], 4);
  printf("init_check:recv : %02x %02x %02x %02x \n", RECV[0], RECV[1], RECV[2],
         RECV[3]);
  if (RECV[0] == 0xFF && RECV[1] == 0xFF)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<init_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0xe9f(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xe99(%rip),%ax
mov    %ax,-0xe(%rbp)
lea    -0x1c(%rbp),%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x12(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    $0x30d40,%edi
call   1070 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x1c(%rbp),%dl
mov    -0x1b(%rbp),%cl
mov    -0x1a(%rbp),%al
lea    0xe4b(%rip),%rdi
movzbl %dl,%esi
movzbl %cl,%edx
movzbl %al,%ecx
movzbl -0x19(%rbp),%r8d
call   1040 <printf@plt>
movzbl -0x1c(%rbp),%eax
cmp    $0xff,%eax
jne    11f8 <init_check+0xa8>
movzbl -0x1b(%rbp),%eax
cmp    $0xff,%eax
jne    11f8 <init_check+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    11ff <init_check+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_check>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movw   $0xbf66,0x14(%rsp)
movl   $0x554433fb,0x10(%rsp)
55
lea    0x6(%rsp),%r14
mov    %r14,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1050 <memset@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x6,%edx
call   1030 <write@plt>
mov    $0x30d40,%edi
call   1070 <usleep@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
movzbl 0x6(%rsp),%esi
movzbl 0x7(%rsp),%edx
movzbl 0x8(%rsp),%ecx
movzbl 0x9(%rsp),%r8d
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
mov    0x6(%rsp),%cl
and    0x7(%rsp),%cl
xor    %eax,%eax
cmp    $0xff,%cl
sete   %al
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.init_check.Check = [6 x i8] c"\FB3DUf\BF"
@.str = [40 x i8] c"init_check:recv : %02x %02x %02x %02x \0A\00"
define i32 @init_check(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [6 x i8]
%6 = alloca [10 x i8]
store i32 %0, i32* %3
%7 = bitcast [6 x i8]* %5 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 10, i32 0)
%10 = load i32, i32* %3
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%12 = call i32 @write(i32 %10, i8* %11, i32 6)
%13 = call i32 @usleep(i32 200000)
%14 = load i32, i32* %3
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 4)
%17 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%18 = load i8, i8* %17
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 1
%20 = load i8, i8* %19
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 2
%22 = load i8, i8* %21
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 3
%24 = load i8, i8* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8 zeroext %18, i8 zeroext %20, i8 zeroext %22, i8 zeroext %24)
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = icmp eq i32 %28, 255
br i1 %29, label %30, label %36
30: ; preds = %1
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %33, 255
br i1 %34, label %35, label %36
35: ; preds = %30
store i32 1, i32* %2
br label %37
36: ; preds = %30, %1
store i32 0, i32* %2
br label %37
37: ; preds = %36, %35
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@__const.init_check.Check = [6 x i8] c"\FB3DUf\BF"
@.str = [40 x i8] c"init_check:recv : %02x %02x %02x %02x \0A\00"
define i32 @init_check(i32 %0) {
%2 = alloca [6 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 10, i32 0)
%7 = call i32 @write(i32 %0, i8* %4, i32 6)
%8 = call i32 @usleep(i32 200000)
%9 = call i32 @read(i32 %0, i8* %5, i32 4)
%10 = load i8, i8* %5
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
%12 = load i8, i8* %11
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
%14 = load i8, i8* %13
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 3
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8 zeroext %10, i8 zeroext %12, i8 zeroext %14, i8 zeroext %16)
%18 = load i8, i8* %5
%19 = icmp eq i8 %18, -1
%20 = load i8, i8* %11
%21 = icmp eq i8 %20, -1
%22 = select i1 %19, i1 %21, i1 false
%23 = zext i1 %22 to i32
ret i32 %23
}