#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*/ wbuf;
typedef int uint8_t;
typedef int /*<<< orphan*/ rbuf;

/* Variables and functions */
int _read(int, int *, int);
int /*<<< orphan*/ _write(int, int *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
uint8_t led_status_get(int fd) {
  uint8_t wbuf[] = {0x06};
  uint8_t rbuf[1];
  _write(fd, wbuf, sizeof(wbuf));
  if (_read(fd, rbuf, sizeof(rbuf)) != 1) {
    perror("read status byte");
    exit(1);
  }
  return rbuf[0];
}


x86 assembly (clang, -O0):
<led_status_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0xeaf(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <_write@plt>
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
mov    $0x4,%edx
call   1050 <_read@plt>
cmp    $0x1,%eax
je     1195 <led_status_get+0x55>
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<led_status_get>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x6,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
call   1030 <_write@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1050 <_read@plt>
cmp    $0x1,%eax
jne    117e <led_status_get+0x3e>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.led_status_get.wbuf = [1 x i32] [i32 6]
@.str = [17 x i8] c"read status byte\00"
define i32 @led_status_get(i32 %0) {
%2 = alloca i32
%3 = alloca [1 x i32]
%4 = alloca [1 x i32]
store i32 %0, i32* %2
%5 = bitcast [1 x i32]* %3 to i8*
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%8 = call i32 @_write(i32 %6, i32* %7, i32 4)
%9 = load i32, i32* %2
%10 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%11 = call i32 @_read(i32 %9, i32* %10, i32 4)
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%18 = load i32, i32* %17
ret i32 %18
}

LLVM IR (-O2):
@.str = [17 x i8] c"read status byte\00"
define i32 @led_status_get(i32 %0) {
%2 = alloca [1 x i32]
%3 = alloca [1 x i32]
%4 = bitcast [1 x i32]* %2 to i8*
%5 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
store i32 6, i32* %5
%6 = bitcast [1 x i32]* %3 to i8*
%7 = call i32 @_write(i32 %0, i32* %5, i32 4)
%8 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%9 = call i32 @_read(i32 %0, i32* %8, i32 4)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
%15 = load i32, i32* %8
ret i32 %15
}