#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*/ fe_status_t;

/* Variables and functions */
int /*<<< orphan*/ FEDumpStatus(int /*<<< orphan*/ *);
int /*<<< orphan*/ FE_READ_STATUS;
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int FEGetStatus(int fd) {
  int result;
  fe_status_t stat;
  if ((result = ioctl(fd, FE_READ_STATUS, &stat) < 0)) {
    perror("FE_READ_STATUS");
    return result;
  }
  printf("FE Status:");
  FEDumpStatus(&stat);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<FEGetStatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0xc(%rbp)
test   $0x1,%al
jne    117f <FEGetStatus+0x3f>
jmp    1196 <FEGetStatus+0x56>
lea    0xe7a(%rip),%rdi
call   1050 <perror@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11be <FEGetStatus+0x7e>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1060 <FEDumpStatus@plt>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FEGetStatus>:
push   %rax
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1050 <ioctl@plt>
test   %rax,%rax
js     118d <FEGetStatus+0x3d>
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
lea    0x4(%rsp),%rdi
call   1070 <FEDumpStatus@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe6c(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@FE_READ_STATUS = global i32 0
@.str = [15 x i8] c"FE_READ_STATUS\00"
@.str.1 = [11 x i8] c"FE Status:\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @FEGetStatus(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = load i32, i32* @FE_READ_STATUS
%8 = call i64 @ioctl(i32 %6, i32 %7, i32* %5)
%9 = icmp slt i64 %8, 0
%10 = zext i1 %9 to i32
store i32 %10, i32* %4
br i1 %9, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %4
store i32 %13, i32* %2
br label %18
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @FEDumpStatus(i32* %5)
%17 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %18
18: ; preds = %14, %11
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@FE_READ_STATUS = global i32 0
@.str = [15 x i8] c"FE_READ_STATUS\00"
@.str.1 = [11 x i8] c"FE Status:\00"
define i32 @FEGetStatus(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @FE_READ_STATUS
%5 = call i64 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %1
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @FEDumpStatus(i32* %2)
%12 = call i32 @putchar(i32 10)
br label %13
13: ; preds = %9, %7
%14 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %14
}