#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 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*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int monitor_frontend(int fe_fd) {
  fe_status_t status;
  uint16_t snr, signal;
  uint32_t ber, uncorrected_blocks;
  do {
    ioctl(fe_fd, FE_READ_STATUS, &status);
    ioctl(fe_fd, FE_READ_SIGNAL_STRENGTH, &signal);
    ioctl(fe_fd, FE_READ_SNR, &snr);
    ioctl(fe_fd, FE_READ_BER, &ber);
    ioctl(fe_fd, FE_READ_UNCORRECTED_BLOCKS, &uncorrected_blocks);
    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");
    usleep(1000000);
    printf("\n");
  } while (1);
  return 0;
}


x86 assembly (clang, -O0):
<monitor_frontend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x4(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    -0x8(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    0x2e13(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11e6 <monitor_frontend+0xb6>
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xf4240,%edi
call   1050 <usleep@plt>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    113b <monitor_frontend+0xb>
jmp    120d <monitor_frontend+0xdd>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monitor_frontend>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%r13
mov    0x2e8c(%rip),%r15
lea    0x8(%rsp),%rbp
lea    0xe98(%rip),%r14
mov    0x2e71(%rip),%r12
jmp    1194 <monitor_frontend+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0xf4240,%edi
call   1060 <usleep@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x4(%rsp),%rdx
call   1050 <ioctl@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x10(%rsp),%rdx
call   1050 <ioctl@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
lea    0x14(%rsp),%rdx
call   1050 <ioctl@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r13,%rdx
call   1050 <ioctl@plt>
mov    (%r15),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1050 <ioctl@plt>
mov    0x4(%rsp),%esi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x8(%rsp),%r9d
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%eax
test   %eax,0x4(%rsp)
je     1180 <monitor_frontend+0x40>
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1180 <monitor_frontend+0x40>

LLVM IR (-O0):
@FE_READ_STATUS = 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 = [62 x i8] c"status %02x | signal %04x | snr %04x | ber %08x | unc %08x | \00"
@FE_HAS_LOCK = global i32 0
@.str.1 = [12 x i8] c"FE_HAS_LOCK\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @monitor_frontend(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %2
br label %8
8: ; preds = %39, %1
%9 = load i32, i32* %2
%10 = load i32, i32* @FE_READ_STATUS
%11 = call i32 @ioctl(i32 %9, i32 %10, i32* %3)
%12 = load i32, i32* %2
%13 = load i32, i32* @FE_READ_SIGNAL_STRENGTH
%14 = call i32 @ioctl(i32 %12, i32 %13, i32* %5)
%15 = load i32, i32* %2
%16 = load i32, i32* @FE_READ_SNR
%17 = call i32 @ioctl(i32 %15, i32 %16, i32* %4)
%18 = load i32, i32* %2
%19 = load i32, i32* @FE_READ_BER
%20 = call i32 @ioctl(i32 %18, i32 %19, i32* %6)
%21 = load i32, i32* %2
%22 = load i32, i32* @FE_READ_UNCORRECTED_BLOCKS
%23 = call i32 @ioctl(i32 %21, i32 %22, i32* %7)
%24 = load i32, i32* %3
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %25, i32 %26, i32 %27, i32 %28)
%30 = load i32, i32* %3
%31 = load i32, i32* @FE_HAS_LOCK
%32 = and i32 %30, %31
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %8
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34, %8
%37 = call i32 @usleep(i32 1000000)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %36
br i1 true, label %8, label %40
40: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@FE_READ_STATUS = 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 = [62 x i8] c"status %02x | signal %04x | snr %04x | ber %08x | unc %08x | \00"
@FE_HAS_LOCK = global i32 0
@.str.1 = [12 x i8] c"FE_HAS_LOCK\00"
define i32 @monitor_frontend(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %2 to i8*
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
br label %12
12: ; preds = %35, %1
%13 = load i32, i32* @FE_READ_STATUS
%14 = call i32 @ioctl(i32 %0, i32 %13, i32* %2)
%15 = load i32, i32* @FE_READ_SIGNAL_STRENGTH
%16 = call i32 @ioctl(i32 %0, i32 %15, i32* %4)
%17 = load i32, i32* @FE_READ_SNR
%18 = call i32 @ioctl(i32 %0, i32 %17, i32* %3)
%19 = load i32, i32* @FE_READ_BER
%20 = call i32 @ioctl(i32 %0, i32 %19, i32* %5)
%21 = load i32, i32* @FE_READ_UNCORRECTED_BLOCKS
%22 = call i32 @ioctl(i32 %0, i32 %21, i32* %6)
%23 = load i32, i32* %2
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %24, i32 %25, i32 %26, i32 %27)
%29 = load i32, i32* %2
%30 = load i32, i32* @FE_HAS_LOCK
%31 = and i32 %30, %29
%32 = icmp eq i32 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %12
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %12
%36 = call i32 @usleep(i32 1000000)
%37 = call i32 @putchar(i32 10)
br label %12
}