#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*/ printf(char *, unsigned char);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, unsigned char *, int);
int check_status(int fd) {
  int ret;
  unsigned char CHECK[] = {0xE5};
  unsigned char RECV[10];
  write(fd, &CHECK[0], 1);
  usleep(10);
  read(fd, &RECV[0], 1);
  printf("Check status : %02x\n", RECV[0]);
  if (RECV[0] == 0x01)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0xeaf(%rip),%al
mov    %al,-0xd(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xd(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0xa,%edi
call   1060 <usleep@plt>
mov    -0x8(%rbp),%edi
lea    -0x17(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
lea    0xe7a(%rip),%rdi
movzbl -0x17(%rbp),%esi
call   1040 <printf@plt>
movzbl -0x17(%rbp),%eax
cmp    $0x1,%eax
jne    11a9 <check_status+0x69>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <check_status+0x70>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_status>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movb   $0xe5,0x5(%rsp)
lea    0x5(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    $0xa,%edi
call   1060 <usleep@plt>
lea    0x6(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1050 <read@plt>
movzbl 0x6(%rsp),%esi
xor    %ebx,%ebx
cmp    $0x1,%esi
setne  %bl
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.check_status.CHECK = [1 x i8] c"\E5"
@.str = [21 x i8] c"Check status : %02x\0A\00"
define i32 @check_status(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1 x i8]
%6 = alloca [10 x i8]
store i32 %0, i32* %3
%7 = bitcast [1 x i8]* %5 to i8*
%8 = load i32, i32* %3
%9 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%10 = call i32 @write(i32 %8, i8* %9, i32 1)
%11 = call i32 @usleep(i32 10)
%12 = load i32, i32* %3
%13 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 1)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%16 = load i8, i8* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %16)
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %23
22: ; preds = %1
store i32 0, i32* %2
br label %24
23: ; preds = %1
store i32 1, i32* %2
br label %24
24: ; preds = %23, %22
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@.str = [21 x i8] c"Check status : %02x\0A\00"
define i32 @check_status(i32 %0) {
%2 = alloca [1 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
store i8 -27, i8* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = call i32 @write(i32 %0, i8* %4, i32 1)
%7 = tail call i32 @usleep(i32 10)
%8 = call i32 @read(i32 %0, i8* %5, i32 1)
%9 = load i8, i8* %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = icmp ne i8 %9, 1
%12 = zext i1 %11 to i32
ret i32 %12
}