#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 uint32_t;
typedef int uint16_t;
typedef int fe_status_t;

/* Variables and functions */
int EIO;
int FE_HAS_LOCK;
int /*<<< orphan*/ FE_READ_BER;
int /*<<< orphan*/ FE_READ_SIGNAL_STRENGTH;
int /*<<< orphan*/ FE_READ_SNR;
int /*<<< orphan*/ FE_READ_STATUS;
int /*<<< orphan*/ FE_READ_UNCORRECTED_BLOCKS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int check_frontend(int fd, int human_readable) {
  fe_status_t status;
  uint16_t snr, signal;
  uint32_t ber, uncorrected_blocks;
  int ret;
  do {
    ret = ioctl(fd, FE_READ_STATUS, &status);
    if (ret == -1) {
      fprintf(stderr, "FE_READ_STATUS failed, err=%d", ret);
      return -EIO;
    }
    ret = ioctl(fd, FE_READ_SIGNAL_STRENGTH, &signal);
    if (ret == -1)
      signal = -2;
    ret = ioctl(fd, FE_READ_SNR, &snr);
    if (ret == -1)
      snr = -2;
    ret = ioctl(fd, FE_READ_BER, &ber);
    if (ret == -1)
      ber = -2;
    ret = ioctl(fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks);
    if (ret == -1)
      uncorrected_blocks = -2;
    if (human_readable) {
      printf("status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | ",
             status, (signal * 100) / 0xffff, (snr * 100) / 0xffff, ber,
             uncorrected_blocks);
    } else {
      printf("status %02x | signal %04x | snr %04x | ber %08x | unc %08x | ",
             status, signal, snr, ber, uncorrected_blocks);
    }
    if (status & FE_HAS_LOCK)
      printf("FE_HAS_LOCK");
    printf("\n");
    usleep(1000000);
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<check_frontend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    119b <check_frontend+0x5b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xe7d(%rip),%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    0x2e3f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    12f7 <check_frontend+0x1b7>
mov    -0x8(%rbp),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11c4 <check_frontend+0x84>
movl   $0xfffffffe,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11ed <check_frontend+0xad>
movl   $0xfffffffe,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2db9(%rip),%rax
mov    (%rax),%esi
lea    -0x1c(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1216 <check_frontend+0xd6>
movl   $0xfffffffe,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    123f <check_frontend+0xff>
movl   $0xfffffffe,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1287 <check_frontend+0x147>
mov    -0x10(%rbp),%esi
imul   $0x64,-0x18(%rbp),%eax
mov    $0xffff,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
imul   $0x64,-0x14(%rbp),%eax
mov    $0xffff,%ecx
cltd
idiv   %ecx
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a6 <check_frontend+0x166>
mov    -0x10(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x20(%rbp),%r9d
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    0x2d30(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     12c9 <check_frontend+0x189>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xf4240,%edi
call   1060 <usleep@plt>
mov    $0x1,%al
test   $0x1,%al
jne    114e <check_frontend+0xe>
jmp    12f0 <check_frontend+0x1b0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_frontend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12ec <check_frontend+0x19c>
lea    0x8(%rsp),%r12
lea    0x4(%rsp),%r13
mov    0x2e51(%rip),%r15
lea    0x10(%rsp),%r14
jmp    11d0 <check_frontend+0x80>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xf4240,%edi
call   1070 <usleep@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     12ec <check_frontend+0x19c>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
lea    0x14(%rsp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11f2 <check_frontend+0xa2>
movl   $0xfffffffe,0x14(%rsp)
ff
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
lea    0xc(%rsp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1214 <check_frontend+0xc4>
movl   $0xfffffffe,0xc(%rsp)
ff
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r12,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1234 <check_frontend+0xe4>
movl   $0xfffffffe,0x8(%rsp)
ff
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r13,%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1254 <check_frontend+0x104>
movl   $0xfffffffe,0x4(%rsp)
ff
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
test   %ebx,%ebx
je     12b0 <check_frontend+0x160>
imul   $0x64,%edx,%eax
movslq %eax,%rdx
imul   $0xffffffff80008001,%rdx,%rax
shr    $0x20,%rax
add    %eax,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0xf,%edx
add    %eax,%edx
imul   $0x64,0xc(%rsp),%eax
movslq %eax,%rcx
imul   $0xffffffff80008001,%rcx,%rax
shr    $0x20,%rax
add    %eax,%ecx
mov    %ecx,%eax
shr    $0x1f,%eax
sar    $0xf,%ecx
add    %eax,%ecx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
lea    0xd71(%rip),%rdi
jmp    12c5 <check_frontend+0x175>
nop
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
lea    0xd95(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%eax
test   %eax,0x10(%rsp)
je     11a0 <check_frontend+0x50>
lea    0xdb8(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <check_frontend+0x50>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
mov    $0xffffffff,%edx
call   1060 <fprintf@plt>
mov    0x2cc3(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FE_READ_STATUS = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"FE_READ_STATUS failed, err=%d\00"
@EIO = global i32 0
@FE_READ_SIGNAL_STRENGTH = global i32 0
@FE_READ_SNR = global i32 0
@FE_READ_BER = global i32 0
@FE_READ_UNCORRECTED_BLOCKS = global i32 0
@.str.1 = [60 x i8] c"status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | \00"
@.str.2 = [62 x i8] c"status %02x | signal %04x | snr %04x | ber %08x | unc %08x | \00"
@FE_HAS_LOCK = global i32 0
@.str.3 = [12 x i8] c"FE_HAS_LOCK\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @check_frontend(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
br label %12
12: ; preds = %83, %2
%13 = load i32, i32* %4
%14 = load i32, i32* @FE_READ_STATUS
%15 = call i32 @ioctl(i32 %13, i32 %14, i32* %6)
store i32 %15, i32* %11
%16 = load i32, i32* %11
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = load i32, i32* @stderr
%20 = load i32, i32* %11
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @EIO
%23 = sub nsw i32 0, %22
store i32 %23, i32* %3
br label %85
24: ; preds = %12
%25 = load i32, i32* %4
%26 = load i32, i32* @FE_READ_SIGNAL_STRENGTH
%27 = call i32 @ioctl(i32 %25, i32 %26, i32* %8)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 -2, i32* %8
br label %31
31: ; preds = %30, %24
%32 = load i32, i32* %4
%33 = load i32, i32* @FE_READ_SNR
%34 = call i32 @ioctl(i32 %32, i32 %33, i32* %7)
store i32 %34, i32* %11
%35 = load i32, i32* %11
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %31
store i32 -2, i32* %7
br label %38
38: ; preds = %37, %31
%39 = load i32, i32* %4
%40 = load i32, i32* @FE_READ_BER
%41 = call i32 @ioctl(i32 %39, i32 %40, i32* %9)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 -2, i32* %9
br label %45
45: ; preds = %44, %38
%46 = load i32, i32* %4
%47 = load i32, i32* @FE_READ_UNCORRECTED_BLOCKS
%48 = call i32 @ioctl(i32 %46, i32 %47, i32* %10)
store i32 %48, i32* %11
%49 = load i32, i32* %11
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 -2, i32* %10
br label %52
52: ; preds = %51, %45
%53 = load i32, i32* %5
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %66
55: ; preds = %52
%56 = load i32, i32* %6
%57 = load i32, i32* %8
%58 = mul nsw i32 %57, 100
%59 = sdiv i32 %58, 65535
%60 = load i32, i32* %7
%61 = mul nsw i32 %60, 100
%62 = sdiv i32 %61, 65535
%63 = load i32, i32* %9
%64 = load i32, i32* %10
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %56, i32 %59, i32 %62, i32 %63, i32 %64)
br label %73
66: ; preds = %52
%67 = load i32, i32* %6
%68 = load i32, i32* %8
%69 = load i32, i32* %7
%70 = load i32, i32* %9
%71 = load i32, i32* %10
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %67, i32 %68, i32 %69, i32 %70, i32 %71)
br label %73
73: ; preds = %66, %55
%74 = load i32, i32* %6
%75 = load i32, i32* @FE_HAS_LOCK
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %80
80: ; preds = %78, %73
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%82 = call i32 @usleep(i32 1000000)
br label %83
83: ; preds = %80
br i1 true, label %12, label %84
84: ; preds = %83
store i32 0, i32* %3
br label %85
85: ; preds = %84, %18
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@FE_READ_STATUS = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"FE_READ_STATUS failed, err=%d\00"
@EIO = global i32 0
@FE_READ_SIGNAL_STRENGTH = global i32 0
@FE_READ_SNR = global i32 0
@FE_READ_BER = global i32 0
@FE_READ_UNCORRECTED_BLOCKS = global i32 0
@.str.1 = [60 x i8] c"status %02x | signal %3u%% | snr %3u%% | ber %d | unc %d | \00"
@.str.2 = [62 x i8] c"status %02x | signal %04x | snr %04x | ber %08x | unc %08x | \00"
@FE_HAS_LOCK = global i32 0
@.str.3 = [12 x i8] c"FE_HAS_LOCK\00"
define i32 @check_frontend(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @FE_READ_STATUS
%14 = call i32 @ioctl(i32 %0, i32 %13, i32* %3)
%15 = icmp eq i32 %14, -1
br i1 %15, label %18, label %16
16: ; preds = %2
%17 = icmp eq i32 %1, 0
br label %23
18: ; preds = %67, %2
%19 = load i32, i32* @stderr
%20 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 -1)
%21 = load i32, i32* @EIO
%22 = sub nsw i32 0, %21
ret i32 %22
23: ; preds = %16, %67
%24 = load i32, i32* @FE_READ_SIGNAL_STRENGTH
%25 = call i32 @ioctl(i32 %0, i32 %24, i32* %5)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -2, i32* %5
br label %28
28: ; preds = %27, %23
%29 = load i32, i32* @FE_READ_SNR
%30 = call i32 @ioctl(i32 %0, i32 %29, i32* %4)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 -2, i32* %4
br label %33
33: ; preds = %32, %28
%34 = load i32, i32* @FE_READ_BER
%35 = call i32 @ioctl(i32 %0, i32 %34, i32* %6)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 -2, i32* %6
br label %38
38: ; preds = %37, %33
%39 = load i32, i32* @FE_READ_UNCORRECTED_BLOCKS
%40 = call i32 @ioctl(i32 %0, i32 %39, i32* %7)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %38
store i32 -2, i32* %7
br label %43
43: ; preds = %42, %38
%44 = load i32, i32* %3
%45 = load i32, i32* %5
br i1 %17, label %55, label %46
46: ; preds = %43
%47 = mul nsw i32 %45, 100
%48 = sdiv i32 %47, 65535
%49 = load i32, i32* %4
%50 = mul nsw i32 %49, 100
%51 = sdiv i32 %50, 65535
%52 = load i32, i32* %6
%53 = load i32, i32* %7
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %48, i32 %51, i32 %52, i32 %53)
br label %60
55: ; preds = %43
%56 = load i32, i32* %4
%57 = load i32, i32* %6
%58 = load i32, i32* %7
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %44, i32 %45, i32 %56, i32 %57, i32 %58)
br label %60
60: ; preds = %55, %46
%61 = load i32, i32* %3
%62 = load i32, i32* @FE_HAS_LOCK
%63 = and i32 %62, %61
%64 = icmp eq i32 %63, 0
br i1 %64, label %67, label %65
65: ; preds = %60
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %67
67: ; preds = %65, %60
%68 = call i32 @putchar(i32 10)
%69 = call i32 @usleep(i32 1000000)
%70 = load i32, i32* @FE_READ_STATUS
%71 = call i32 @ioctl(i32 %0, i32 %70, i32* %3)
%72 = icmp eq i32 %71, -1
br i1 %72, label %18, label %23
}