#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*/ FE_READ_BER;
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned int);
int FEDumpBER(int fd) {
  unsigned int ber;
  int result;
  if ((result = ioctl(fd, FE_READ_BER, &ber) < 0)) {
    perror("FE_READ_BER");
    return result;
  }
  printf("FE BER: %d\n", ber);
  return 0;
}


x86 assembly (clang, -O0):
<FEDumpBER>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e9b(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x10(%rbp)
test   $0x1,%al
jne    116f <FEDumpBER+0x3f>
jmp    1186 <FEDumpBER+0x56>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119c <FEDumpBER+0x6c>
mov    -0xc(%rbp),%esi
lea    0xe7c(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FEDumpBER>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
call   1040 <ioctl@plt>
test   %rax,%rax
js     115d <FEDumpBER+0x2d>
mov    0x4(%rsp),%esi
lea    0xeb8(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe9c(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@FE_READ_BER = global i32 0
@.str = [12 x i8] c"FE_READ_BER\00"
@.str.1 = [12 x i8] c"FE BER: %d\0A\00"
define i32 @FEDumpBER(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_BER
%8 = call i64 @ioctl(i32 %6, i32 %7, i32* %4)
%9 = icmp slt i64 %8, 0
%10 = zext i1 %9 to i32
store i32 %10, i32* %5
br i1 %9, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* %5
store i32 %13, i32* %2
br label %17
14: ; preds = %1
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 0, i32* %2
br label %17
17: ; preds = %14, %11
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@FE_READ_BER = global i32 0
@.str = [12 x i8] c"FE_READ_BER\00"
@.str.1 = [12 x i8] c"FE BER: %d\0A\00"
define i32 @FEDumpBER(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @FE_READ_BER
%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 ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ 1, %7 ], [ 0, %9 ]
ret i32 %13
}