#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 char *uint16_t;
struct timeval {
  int tv_sec;
};
struct dvb_frontend_parameters {
  scalar_t__ type;
  int frequency;
  int status;
};
struct dvb_frontend_info {
  scalar_t__ type;
  int frequency;
  int status;
};
struct dvb_frontend_event {
  scalar_t__ type;
  int frequency;
  int status;
};
typedef int /*<<< orphan*/ fe_dev;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ FE_GET_EVENT;
int /*<<< orphan*/ FE_GET_FRONTEND;
int /*<<< orphan*/ FE_GET_INFO;
int FE_HAS_LOCK;
scalar_t__ FE_QPSK;
int /*<<< orphan*/ FE_SET_FRONTEND;
int O_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int PATH_MAX;
unsigned long abs(int);
scalar_t__ do_diseqc(int, unsigned int, char, int);
scalar_t__ errno;
int /*<<< orphan*/ error(char *, char *);
int /*<<< orphan*/ fatal(char *, char *, ...);
int /*<<< orphan*/ get_tune_params(scalar_t__, char *,
                                   struct dvb_frontend_parameters *, char *,
                                   unsigned int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dvb_frontend_parameters *);
int open(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, unsigned int);
int /*<<< orphan*/ strerror(scalar_t__);
int /*<<< orphan*/ verbose(char *, int);
int /*<<< orphan*/ vverbose(char *, ...);
bool tune_service_id(unsigned int adapter, unsigned int frontend,
                     unsigned int timeout, uint16_t service_id, int *tuner_fd) {
  char fe_dev[PATH_MAX];
  bool got_info;
  struct dvb_frontend_info fe_info;
  struct dvb_frontend_parameters current_params;
  struct dvb_frontend_parameters needed_params;
  char polarity;
  unsigned int sat_no;
  bool hi_lo;
  struct dvb_frontend_event event;
  bool lock;
  static int fe_fd = -1;
  static bool first_time = true;
  if (fe_fd < 0) {
    snprintf(fe_dev, sizeof(fe_dev), "/dev/dvb/adapter%u/frontend%u", adapter,
             frontend);
    if ((fe_fd = open(fe_dev, O_RDWR | O_NONBLOCK)) < 0) {
      error("Unable to open '%s' read/write; you will not be able to retune",
            fe_dev);
      if ((fe_fd = open(fe_dev, O_RDONLY | O_NONBLOCK)) < 0)
        fatal("open '%s': %s", fe_dev, strerror(errno));
      first_time = false;
    }
  }
  vverbose("Getting frontend info");
  do {
    got_info = (ioctl(fe_fd, FE_GET_INFO, &fe_info) >= 0);
    if (!got_info && errno != EINTR)
      fatal("ioctl FE_GET_INFO: %s", strerror(errno));
  } while (!got_info);
  if (ioctl(fe_fd, FE_GET_FRONTEND, &current_params) < 0)
    fatal("ioctl FE_GET_FRONTEND: %s", strerror(errno));
  if (!get_tune_params(fe_info.type, service_id, &needed_params, &polarity,
                       &sat_no)) {
    error("service_id %u not found in channels.conf file", service_id);
    return false;
  }
  vverbose("Current frequency %u; needed %u; first_time=%d",
           current_params.frequency, needed_params.frequency, first_time);
  if (first_time ||
      abs(current_params.frequency - needed_params.frequency) >= 1000UL) {
    first_time = false;
    verbose("Retuning to frequency %u", needed_params.frequency);
    while (ioctl(fe_fd, FE_GET_EVENT, &event) >= 0)
      ;
    if (fe_info.type == FE_QPSK) {
      if (needed_params.frequency < (11700 * 1000UL)) {
        needed_params.frequency -= (9750 * 1000UL);
        hi_lo = false;
      } else {
        needed_params.frequency -= (10600 * 1000UL);
        hi_lo = true;
      }
      if (do_diseqc(fe_fd, sat_no, polarity, hi_lo) < 0)
        error("DISEQC command failed for service_id %u", service_id);
    }
    if (ioctl(fe_fd, FE_SET_FRONTEND, &needed_params) < 0)
      fatal("Unable to retune: ioctl FE_SET_FRONTEND: %s", strerror(errno));
    vverbose("Waiting for tuner to lock on");
    struct timeval start, end;
    gettimeofday(&start, NULL);
    lock = false;
    while (!lock) {
      if (ioctl(fe_fd, FE_GET_EVENT, &event) >= 0)
        lock = event.status & FE_HAS_LOCK;
      gettimeofday(&end, NULL);
      if (end.tv_sec - start.tv_sec > 120)
        return false;
    }
    vverbose("Retuned");
  }
  *tuner_fd = fe_fd;
  return true;
}


x86 assembly (clang, -O0):
<tune_service_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xb0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
cmpl   $0x0,0x2e67(%rip)
jge    12e4 <tune_service_id+0x124>
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%ecx
mov    -0xc(%rbp),%r8d
lea    0xdc3(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0xa8(%rbp),%rdi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
mov    0x2d6f(%rip),%rax
or     (%rax),%esi
call   10a0 <open@plt>
mov    %eax,0x2e1a(%rip)
cmp    $0x0,%eax
jge    12df <tune_service_id+0x11f>
mov    -0xa8(%rbp),%rsi
lea    0xda1(%rip),%rdi
call   1090 <error@plt>
mov    -0xa8(%rbp),%rdi
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
mov    0x2d2f(%rip),%rax
or     (%rax),%esi
call   10a0 <open@plt>
mov    %eax,0x2dda(%rip)
cmp    $0x0,%eax
jge    12d5 <tune_service_id+0x115>
mov    0x2cea(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
mov    -0xa8(%rbp),%rsi
mov    %eax,%edx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   10d0 <fatal@plt>
movl   $0x0,0x2da5(%rip)
jmp    12e4 <tune_service_id+0x124>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1080 <vverbose@plt>
mov    0x2d88(%rip),%edi
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    135d <tune_service_id+0x19d>
mov    0x2c76(%rip),%rax
mov    (%rax),%rax
mov    0x2c64(%rip),%rcx
cmp    (%rcx),%rax
je     135d <tune_service_id+0x19d>
mov    0x2c5c(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
movslq %eax,%rsi
lea    0xd2b(%rip),%rdi
mov    $0x0,%al
call   10d0 <fatal@plt>
jmp    1362 <tune_service_id+0x1a2>
cmpl   $0x0,-0x34(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12f2 <tune_service_id+0x132>
mov    0x2d07(%rip),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    13b5 <tune_service_id+0x1f5>
mov    0x2c04(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
movslq %eax,%rsi
lea    0xce9(%rip),%rdi
mov    $0x0,%al
call   10d0 <fatal@plt>
mov    -0x48(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x68(%rbp),%rdx
lea    -0x69(%rbp),%rcx
lea    -0x70(%rbp),%r8
call   10e0 <get_tune_params@plt>
cmp    $0x0,%eax
jne    13fd <tune_service_id+0x23d>
mov    -0x18(%rbp),%rsi
lea    0xccf(%rip),%rdi
call   1090 <error@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    162a <tune_service_id+0x46a>
mov    -0x50(%rbp),%esi
mov    -0x60(%rbp),%edx
mov    0x2c7b(%rip),%ecx
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1080 <vverbose@plt>
cmpl   $0x0,0x2c66(%rip)
jne    143b <tune_service_id+0x27b>
mov    -0x50(%rbp),%edi
sub    -0x60(%rbp),%edi
call   1030 <abs@plt>
cmp    $0x3e8,%rax
jb     160d <tune_service_id+0x44d>
movl   $0x0,0x2c3f(%rip)
mov    -0x60(%rbp),%esi
lea    0xcbf(%rip),%rdi
call   10b0 <verbose@plt>
mov    0x2c26(%rip),%edi
mov    0x2b27(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jl     147e <tune_service_id+0x2be>
jmp    1454 <tune_service_id+0x294>
mov    -0x48(%rbp),%rax
mov    0x2b07(%rip),%rcx
cmp    (%rcx),%rax
jne    1505 <tune_service_id+0x345>
movslq -0x60(%rbp),%rax
cmp    $0xb28720,%rax
jae    14bb <tune_service_id+0x2fb>
movslq -0x60(%rbp),%rax
sub    $0x94c5f0,%rax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x74(%rbp)
jmp    14cf <tune_service_id+0x30f>
movslq -0x60(%rbp),%rax
sub    $0xa1be40,%rax
mov    %eax,-0x60(%rbp)
movl   $0x1,-0x74(%rbp)
mov    0x2bab(%rip),%edi
mov    -0x70(%rbp),%esi
mov    -0x69(%rbp),%al
mov    -0x74(%rbp),%ecx
movsbl %al,%edx
call   1070 <do_diseqc@plt>
cmp    $0x0,%rax
jge    1500 <tune_service_id+0x340>
mov    -0x18(%rbp),%rsi
lea    0xc2c(%rip),%rdi
call   1090 <error@plt>
jmp    1505 <tune_service_id+0x345>
mov    0x2b75(%rip),%edi
mov    0x2ace(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1547 <tune_service_id+0x387>
mov    0x2a72(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
movslq %eax,%rsi
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   10d0 <fatal@plt>
lea    0xc2d(%rip),%rdi
mov    $0x0,%al
call   1080 <vverbose@plt>
lea    -0x98(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
movl   $0x0,-0x8c(%rbp)
cmpl   $0x0,-0x8c(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1588 <tune_service_id+0x3c8>
jmp    15ff <tune_service_id+0x43f>
mov    0x2af2(%rip),%edi
mov    0x29f3(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jl     15bf <tune_service_id+0x3ff>
mov    -0x7c(%rbp),%eax
mov    0x2a01(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x8c(%rbp)
lea    -0xa0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0xa0(%rbp),%eax
sub    -0x98(%rbp),%eax
cmp    $0x78,%eax
jle    15fa <tune_service_id+0x43a>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
jmp    162a <tune_service_id+0x46a>
jmp    156f <tune_service_id+0x3af>
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1080 <vverbose@plt>
mov    0x2a6d(%rip),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x90(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tune_service_id>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8,-0x58(%rbp)
mov    %rcx,-0x60(%rbp)
mov    %esi,%r8d
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
cmpl   $0x0,0x2e83(%rip)
jns    128f <tune_service_id+0xcf>
mov    %edi,%ecx
lea    0xdf4(%rip),%rdx
mov    %rbx,%rdi
call   1040 <snprintf@plt>
mov    0x2db5(%rip),%rax
mov    0x2da6(%rip),%r14
mov    (%r14),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,0x2e4b(%rip)
test   %eax,%eax
jns    128f <tune_service_id+0xcf>
lea    0xdde(%rip),%rdi
mov    %rbx,%rsi
call   1090 <error@plt>
mov    0x2d71(%rip),%rax
mov    (%r14),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   10a0 <open@plt>
mov    %eax,0x2e1e(%rip)
test   %eax,%eax
jns    1288 <tune_service_id+0xc8>
mov    0x2d33(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
lea    0xde1(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fatal@plt>
movb   $0x1,0x2e05(%rip)
lea    0xdd5(%rip),%rdi
xor    %eax,%eax
call   1080 <vverbose@plt>
mov    0x2ddd(%rip),%edi
mov    0x2d06(%rip),%r13
mov    0x0(%r13),%esi
lea    -0x70(%rbp),%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
js     14bc <tune_service_id+0x2fc>
mov    0x2dba(%rip),%edi
mov    0x2d2b(%rip),%rax
mov    (%rax),%esi
lea    -0x90(%rbp),%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
mov    -0x60(%rbp),%r14
jns    1304 <tune_service_id+0x144>
mov    0x2cb5(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
movslq %eax,%rsi
lea    0xd9a(%rip),%rdi
xor    %eax,%eax
call   10d0 <fatal@plt>
mov    -0x70(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    -0x29(%rbp),%rcx
lea    -0x3c(%rbp),%r8
mov    %r14,%rsi
call   10e0 <get_tune_params@plt>
test   %eax,%eax
je     1517 <tune_service_id+0x357>
mov    -0x88(%rbp),%esi
mov    -0x48(%rbp),%edx
movzbl 0x2d60(%rip),%ecx
xor    $0x1,%ecx
lea    0xda1(%rip),%rdi
xor    %eax,%eax
call   1080 <vverbose@plt>
cmpb   $0x1,0x2d48(%rip)
jne    1368 <tune_service_id+0x1a8>
mov    -0x88(%rbp),%edi
sub    -0x48(%rbp),%edi
call   1030 <abs@plt>
cmp    $0x3e8,%rax
jb     1538 <tune_service_id+0x378>
movb   $0x1,0x2d25(%rip)
mov    -0x48(%rbp),%esi
lea    0xd95(%rip),%rdi
call   10b0 <verbose@plt>
mov    0x2c03(%rip),%r12
lea    -0x80(%rbp),%rbx
nopl   0x0(%rax)
mov    0x2cea(%rip),%edi
mov    (%r12),%esi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
jns    1390 <tune_service_id+0x1d0>
mov    -0x70(%rbp),%rax
mov    0x2bde(%rip),%rcx
cmp    (%rcx),%rax
jne    13fc <tune_service_id+0x23c>
mov    -0x48(%rbp),%eax
lea    -0xa1be40(%rax),%edx
lea    -0x94c5f0(%rax),%esi
xor    %ecx,%ecx
cmp    $0xb28720,%eax
setae  %cl
cmovae %edx,%esi
mov    %esi,-0x48(%rbp)
mov    0x2ca4(%rip),%edi
mov    -0x3c(%rbp),%esi
movsbl -0x29(%rbp),%edx
call   1070 <do_diseqc@plt>
test   %rax,%rax
jns    13fc <tune_service_id+0x23c>
lea    0xd33(%rip),%rdi
mov    %r14,%rsi
call   1090 <error@plt>
mov    0x2c7e(%rip),%edi
mov    0x2bd7(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
jns    1439 <tune_service_id+0x279>
mov    0x2b80(%rip),%rax
mov    (%rax),%rdi
call   10c0 <strerror@plt>
movslq %eax,%rsi
lea    0xd1d(%rip),%rdi
xor    %eax,%eax
call   10d0 <fatal@plt>
lea    0xd3b(%rip),%rdi
xor    %eax,%eax
call   1080 <vverbose@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x38(%rbp),%r14d
mov    0x2b5b(%rip),%r13
lea    -0x30(%rbp),%rbx
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %r15d,%r15d
jne    152a <tune_service_id+0x36a>
mov    0x2c01(%rip),%edi
mov    (%r12),%esi
lea    -0x80(%rbp),%rdx
call   1060 <ioctl@plt>
mov    0x0(%r13),%r15d
and    -0x74(%rbp),%r15d
test   %rax,%rax
mov    $0x0,%eax
cmovs  %eax,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%eax
sub    %r14d,%eax
cmp    $0x79,%eax
jl     1470 <tune_service_id+0x2b0>
xor    %eax,%eax
jmp    1549 <tune_service_id+0x389>
mov    0x2add(%rip),%r14
mov    0x2ace(%rip),%r15
lea    -0x70(%rbp),%rbx
lea    0xbac(%rip),%r12
jmp    14fb <tune_service_id+0x33b>
nopw   0x0(%rax,%rax,1)
mov    0x2b9a(%rip),%edi
mov    0x0(%r13),%esi
mov    %rbx,%rdx
call   1060 <ioctl@plt>
test   %rax,%rax
jns    12c0 <tune_service_id+0x100>
mov    (%r14),%rdi
cmp    (%r15),%rdi
je     14e0 <tune_service_id+0x320>
call   10c0 <strerror@plt>
movslq %eax,%rsi
mov    %r12,%rdi
xor    %eax,%eax
call   10d0 <fatal@plt>
jmp    14e0 <tune_service_id+0x320>
lea    0xb93(%rip),%rdi
mov    %r14,%rsi
call   1090 <error@plt>
xor    %eax,%eax
jmp    1549 <tune_service_id+0x389>
lea    0xc67(%rip),%rdi
xor    %eax,%eax
call   1080 <vverbose@plt>
mov    0x2b42(%rip),%eax
mov    -0x58(%rbp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dvb_frontend_info = type { i64, i32, i32 }
%struct.dvb_frontend_parameters = type { i64, i32, i32 }
%struct.dvb_frontend_event = type { i64, i32, i32 }
%struct.timeval = type { i32 }
@PATH_MAX = global i32 0
@tune_service_id.fe_fd = internal global i32 -1
@tune_service_id.first_time = internal global i32 1
@.str = [30 x i8] c"/dev/dvb/adapter%u/frontend%u\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [63 x i8] c"Unable to open '%s' read/write; you will not be able to retune\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"open '%s': %s\00"
@errno = global i64 0
@.str.3 = [22 x i8] c"Getting frontend info\00"
@FE_GET_INFO = global i32 0
@EINTR = global i64 0
@.str.4 = [22 x i8] c"ioctl FE_GET_INFO: %s\00"
@FE_GET_FRONTEND = global i32 0
@.str.5 = [26 x i8] c"ioctl FE_GET_FRONTEND: %s\00"
@.str.6 = [46 x i8] c"service_id %u not found in channels.conf file\00"
@.str.7 = [47 x i8] c"Current frequency %u; needed %u; first_time=%d\00"
@.str.8 = [25 x i8] c"Retuning to frequency %u\00"
@FE_GET_EVENT = global i32 0
@FE_QPSK = global i64 0
@.str.9 = [40 x i8] c"DISEQC command failed for service_id %u\00"
@FE_SET_FRONTEND = global i32 0
@.str.10 = [44 x i8] c"Unable to retune: ioctl FE_SET_FRONTEND: %s\00"
@.str.11 = [29 x i8] c"Waiting for tuner to lock on\00"
@FE_HAS_LOCK = global i32 0
@.str.12 = [8 x i8] c"Retuned\00"
define i32 @tune_service_id(i32 %0, i32 %1, i32 %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca %struct.dvb_frontend_info
%16 = alloca %struct.dvb_frontend_parameters
%17 = alloca %struct.dvb_frontend_parameters
%18 = alloca i8
%19 = alloca i32
%20 = alloca i32
%21 = alloca %struct.dvb_frontend_event
%22 = alloca i32
%23 = alloca i32
%24 = alloca %struct.timeval
%25 = alloca %struct.timeval
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32* %4, i32** %11
%26 = load i32, i32* @PATH_MAX
%27 = zext i32 %26 to i64
%28 = call i8* @llvm.stacksave()
store i8* %28, i8** %12
%29 = alloca i8, i64 %27
store i64 %27, i64* %13
%30 = load i32, i32* @tune_service_id.fe_fd
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %55
32: ; preds = %5
%33 = trunc i64 %27 to i32
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 @snprintf(i8* %29, i32 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32, i32* @O_RDWR
%38 = load i32, i32* @O_NONBLOCK
%39 = or i32 %37, %38
%40 = call i32 @open(i8* %29, i32 %39)
store i32 %40, i32* @tune_service_id.fe_fd
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %54
42: ; preds = %32
%43 = call i32 @error(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%44 = load i32, i32* @O_RDONLY
%45 = load i32, i32* @O_NONBLOCK
%46 = or i32 %44, %45
%47 = call i32 @open(i8* %29, i32 %46)
store i32 %47, i32* @tune_service_id.fe_fd
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %42
%50 = load i64, i64* @errno
%51 = call i32 @strerror(i64 %50)
%52 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %29, i32 %51)
br label %53
53: ; preds = %49, %42
store i32 0, i32* @tune_service_id.first_time
br label %54
54: ; preds = %53, %32
br label %55
55: ; preds = %54, %5
%56 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %57
57: ; preds = %77, %55
%58 = load i32, i32* @tune_service_id.fe_fd
%59 = load i32, i32* @FE_GET_INFO
%60 = bitcast %struct.dvb_frontend_info* %15 to %struct.dvb_frontend_parameters*
%61 = call i64 @ioctl(i32 %58, i32 %59, %struct.dvb_frontend_parameters* %60)
%62 = icmp sge i64 %61, 0
%63 = zext i1 %62 to i32
store i32 %63, i32* %14
%64 = load i32, i32* %14
%65 = icmp ne i32 %64, 0
br i1 %65, label %76, label %66
66: ; preds = %57
%67 = load i64, i64* @errno
%68 = load i64, i64* @EINTR
%69 = icmp ne i64 %67, %68
br i1 %69, label %70, label %76
70: ; preds = %66
%71 = load i64, i64* @errno
%72 = call i32 @strerror(i64 %71)
%73 = sext i32 %72 to i64
%74 = inttoptr i64 %73 to i8*
%75 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %70, %66, %57
br label %77
77: ; preds = %76
%78 = load i32, i32* %14
%79 = icmp ne i32 %78, 0
%80 = xor i1 %79, true
br i1 %80, label %57, label %81
81: ; preds = %77
%82 = load i32, i32* @tune_service_id.fe_fd
%83 = load i32, i32* @FE_GET_FRONTEND
%84 = call i64 @ioctl(i32 %82, i32 %83, %struct.dvb_frontend_parameters* %16)
%85 = icmp slt i64 %84, 0
br i1 %85, label %86, label %92
86: ; preds = %81
%87 = load i64, i64* @errno
%88 = call i32 @strerror(i64 %87)
%89 = sext i32 %88 to i64
%90 = inttoptr i64 %89 to i8*
%91 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %86, %81
%93 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %15, i32 0, i32 0
%94 = load i64, i64* %93
%95 = load i8*, i8** %10
%96 = call i32 @get_tune_params(i64 %94, i8* %95, %struct.dvb_frontend_parameters* %17, i8* %18, i32* %19)
%97 = icmp ne i32 %96, 0
br i1 %97, label %101, label %98
98: ; preds = %92
%99 = load i8*, i8** %10
%100 = call i32 @error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %99)
store i32 0, i32* %6
store i32 1, i32* %23
br label %206
101: ; preds = %92
%102 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %16, i32 0, i32 1
%103 = load i32, i32* %102
%104 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%105 = load i32, i32* %104
%106 = load i32, i32* @tune_service_id.first_time
%107 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %103, i32 %105, i32 %106)
%108 = load i32, i32* @tune_service_id.first_time
%109 = icmp ne i32 %108, 0
br i1 %109, label %118, label %110
110: ; preds = %101
%111 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %16, i32 0, i32 1
%112 = load i32, i32* %111
%113 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%114 = load i32, i32* %113
%115 = sub nsw i32 %112, %114
%116 = call i64 @abs(i32 %115)
%117 = icmp uge i64 %116, 1000
br i1 %117, label %118, label %203
118: ; preds = %110, %101
store i32 0, i32* @tune_service_id.first_time
%119 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%120 = load i32, i32* %119
%121 = call i32 @verbose(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %120)
br label %122
122: ; preds = %128, %118
%123 = load i32, i32* @tune_service_id.fe_fd
%124 = load i32, i32* @FE_GET_EVENT
%125 = bitcast %struct.dvb_frontend_event* %21 to %struct.dvb_frontend_parameters*
%126 = call i64 @ioctl(i32 %123, i32 %124, %struct.dvb_frontend_parameters* %125)
%127 = icmp sge i64 %126, 0
br i1 %127, label %128, label %129
128: ; preds = %122
br label %122
129: ; preds = %122
%130 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %15, i32 0, i32 0
%131 = load i64, i64* %130
%132 = load i64, i64* @FE_QPSK
%133 = icmp eq i64 %131, %132
br i1 %133, label %134, label %162
134: ; preds = %129
%135 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%136 = load i32, i32* %135
%137 = sext i32 %136 to i64
%138 = icmp ult i64 %137, 11700000
br i1 %138, label %139, label %145
139: ; preds = %134
%140 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%141 = load i32, i32* %140
%142 = sext i32 %141 to i64
%143 = sub i64 %142, 9750000
%144 = trunc i64 %143 to i32
store i32 %144, i32* %140
store i32 0, i32* %20
br label %151
145: ; preds = %134
%146 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %17, i32 0, i32 1
%147 = load i32, i32* %146
%148 = sext i32 %147 to i64
%149 = sub i64 %148, 10600000
%150 = trunc i64 %149 to i32
store i32 %150, i32* %146
store i32 1, i32* %20
br label %151
151: ; preds = %145, %139
%152 = load i32, i32* @tune_service_id.fe_fd
%153 = load i32, i32* %19
%154 = load i8, i8* %18
%155 = load i32, i32* %20
%156 = call i64 @do_diseqc(i32 %152, i32 %153, i8 signext %154, i32 %155)
%157 = icmp slt i64 %156, 0
br i1 %157, label %158, label %161
158: ; preds = %151
%159 = load i8*, i8** %10
%160 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8* %159)
br label %161
161: ; preds = %158, %151
br label %162
162: ; preds = %161, %129
%163 = load i32, i32* @tune_service_id.fe_fd
%164 = load i32, i32* @FE_SET_FRONTEND
%165 = call i64 @ioctl(i32 %163, i32 %164, %struct.dvb_frontend_parameters* %17)
%166 = icmp slt i64 %165, 0
br i1 %166, label %167, label %173
167: ; preds = %162
%168 = load i64, i64* @errno
%169 = call i32 @strerror(i64 %168)
%170 = sext i32 %169 to i64
%171 = inttoptr i64 %170 to i8*
%172 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i8* %171)
br label %173
173: ; preds = %167, %162
%174 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%175 = call i32 @gettimeofday(%struct.timeval* %24, i32* null)
store i32 0, i32* %22
br label %176
176: ; preds = %200, %173
%177 = load i32, i32* %22
%178 = icmp ne i32 %177, 0
%179 = xor i1 %178, true
br i1 %179, label %180, label %201
180: ; preds = %176
%181 = load i32, i32* @tune_service_id.fe_fd
%182 = load i32, i32* @FE_GET_EVENT
%183 = bitcast %struct.dvb_frontend_event* %21 to %struct.dvb_frontend_parameters*
%184 = call i64 @ioctl(i32 %181, i32 %182, %struct.dvb_frontend_parameters* %183)
%185 = icmp sge i64 %184, 0
br i1 %185, label %186, label %191
186: ; preds = %180
%187 = getelementptr inbounds %struct.dvb_frontend_event, %struct.dvb_frontend_event* %21, i32 0, i32 2
%188 = load i32, i32* %187
%189 = load i32, i32* @FE_HAS_LOCK
%190 = and i32 %188, %189
store i32 %190, i32* %22
br label %191
191: ; preds = %186, %180
%192 = call i32 @gettimeofday(%struct.timeval* %25, i32* null)
%193 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 0
%194 = load i32, i32* %193
%195 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 0
%196 = load i32, i32* %195
%197 = sub nsw i32 %194, %196
%198 = icmp sgt i32 %197, 120
br i1 %198, label %199, label %200
199: ; preds = %191
store i32 0, i32* %6
store i32 1, i32* %23
br label %206
200: ; preds = %191
br label %176
201: ; preds = %176
%202 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
br label %203
203: ; preds = %201, %110
%204 = load i32, i32* @tune_service_id.fe_fd
%205 = load i32*, i32** %11
store i32 %204, i32* %205
store i32 1, i32* %6
store i32 1, i32* %23
br label %206
206: ; preds = %203, %199, %98
%207 = load i8*, i8** %12
%208 = load i32, i32* %6
ret i32 %208
}

LLVM IR (-O2):
%struct.dvb_frontend_info = type { i64, i32, i32 }
%struct.dvb_frontend_parameters = type { i64, i32, i32 }
%struct.dvb_frontend_event = type { i64, i32, i32 }
%struct.timeval = type { i32 }
@PATH_MAX = global i32 0
@tune_service_id.fe_fd = internal unnamed_addr global i32 -1
@tune_service_id.first_time = internal unnamed_addr global i1 false
@.str = [30 x i8] c"/dev/dvb/adapter%u/frontend%u\00"
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [63 x i8] c"Unable to open '%s' read/write; you will not be able to retune\00"
@O_RDONLY = global i32 0
@.str.2 = [14 x i8] c"open '%s': %s\00"
@errno = global i64 0
@.str.3 = [22 x i8] c"Getting frontend info\00"
@FE_GET_INFO = global i32 0
@EINTR = global i64 0
@.str.4 = [22 x i8] c"ioctl FE_GET_INFO: %s\00"
@FE_GET_FRONTEND = global i32 0
@.str.5 = [26 x i8] c"ioctl FE_GET_FRONTEND: %s\00"
@.str.6 = [46 x i8] c"service_id %u not found in channels.conf file\00"
@.str.7 = [47 x i8] c"Current frequency %u; needed %u; first_time=%d\00"
@.str.8 = [25 x i8] c"Retuning to frequency %u\00"
@FE_GET_EVENT = global i32 0
@FE_QPSK = global i64 0
@.str.9 = [40 x i8] c"DISEQC command failed for service_id %u\00"
@FE_SET_FRONTEND = global i32 0
@.str.10 = [44 x i8] c"Unable to retune: ioctl FE_SET_FRONTEND: %s\00"
@.str.11 = [29 x i8] c"Waiting for tuner to lock on\00"
@FE_HAS_LOCK = global i32 0
@.str.12 = [8 x i8] c"Retuned\00"
define i32 @tune_service_id(i32 %0, i32 %1, i32 %2, i8* %3, i32* nocapture writeonly %4) {
%6 = alloca %struct.dvb_frontend_info
%7 = alloca %struct.dvb_frontend_parameters
%8 = alloca %struct.dvb_frontend_parameters
%9 = alloca i8
%10 = alloca i32
%11 = alloca %struct.dvb_frontend_event
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = load i32, i32* @PATH_MAX
%15 = zext i32 %14 to i64
%16 = alloca i8, i64 %15
%17 = bitcast %struct.dvb_frontend_info* %6 to i8*
%18 = bitcast %struct.dvb_frontend_parameters* %7 to i8*
%19 = bitcast %struct.dvb_frontend_parameters* %8 to i8*
%20 = bitcast i32* %10 to i8*
%21 = bitcast %struct.dvb_frontend_event* %11 to i8*
%22 = load i32, i32* @tune_service_id.fe_fd
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %5
%25 = call i32 @snprintf(i8* %16, i32 %14, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_NONBLOCK
%28 = or i32 %27, %26
%29 = call i32 @open(i8* %16, i32 %28)
store i32 %29, i32* @tune_service_id.fe_fd
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %24
%32 = call i32 @error(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%33 = load i32, i32* @O_RDONLY
%34 = load i32, i32* @O_NONBLOCK
%35 = or i32 %34, %33
%36 = call i32 @open(i8* %16, i32 %35)
store i32 %36, i32* @tune_service_id.fe_fd
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i64, i64* @errno
%40 = call i32 @strerror(i64 %39)
%41 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %16, i32 %40)
br label %42
42: ; preds = %38, %31
store i1 true, i1* @tune_service_id.first_time
br label %43
43: ; preds = %24, %42, %5
%44 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%45 = bitcast %struct.dvb_frontend_info* %6 to %struct.dvb_frontend_parameters*
%46 = load i32, i32* @tune_service_id.fe_fd
%47 = load i32, i32* @FE_GET_INFO
%48 = call i64 @ioctl(i32 %46, i32 %47, %struct.dvb_frontend_parameters* %45)
%49 = icmp sgt i64 %48, -1
br i1 %49, label %64, label %50
50: ; preds = %43, %59
%51 = load i64, i64* @errno
%52 = load i64, i64* @EINTR
%53 = icmp eq i64 %51, %52
br i1 %53, label %59, label %54
54: ; preds = %50
%55 = call i32 @strerror(i64 %51)
%56 = sext i32 %55 to i64
%57 = inttoptr i64 %56 to i8*
%58 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %50, %54
%60 = load i32, i32* @tune_service_id.fe_fd
%61 = load i32, i32* @FE_GET_INFO
%62 = call i64 @ioctl(i32 %60, i32 %61, %struct.dvb_frontend_parameters* %45)
%63 = icmp sgt i64 %62, -1
br i1 %63, label %64, label %50
64: ; preds = %59, %43
%65 = load i32, i32* @tune_service_id.fe_fd
%66 = load i32, i32* @FE_GET_FRONTEND
%67 = call i64 @ioctl(i32 %65, i32 %66, %struct.dvb_frontend_parameters* %7)
%68 = icmp slt i64 %67, 0
br i1 %68, label %69, label %75
69: ; preds = %64
%70 = load i64, i64* @errno
%71 = call i32 @strerror(i64 %70)
%72 = sext i32 %71 to i64
%73 = inttoptr i64 %72 to i8*
%74 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %69, %64
%76 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %6, i64 0, i32 0
%77 = load i64, i64* %76
%78 = call i32 @get_tune_params(i64 %77, i8* %3, %struct.dvb_frontend_parameters* %8, i8* %9, i32* %10)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %75
%81 = call i32 @error(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0), i8* %3)
br label %166
82: ; preds = %75
%83 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %7, i64 0, i32 1
%84 = load i32, i32* %83
%85 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %8, i64 0, i32 1
%86 = load i32, i32* %85
%87 = load i1, i1* @tune_service_id.first_time
%88 = xor i1 %87, true
%89 = zext i1 %88 to i32
%90 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %84, i32 %86, i32 %89)
%91 = load i1, i1* @tune_service_id.first_time
br i1 %91, label %92, label %98
92: ; preds = %82
%93 = load i32, i32* %83
%94 = load i32, i32* %85
%95 = sub nsw i32 %93, %94
%96 = call i64 @abs(i32 %95)
%97 = icmp ugt i64 %96, 999
br i1 %97, label %98, label %164
98: ; preds = %92, %82
store i1 true, i1* @tune_service_id.first_time
%99 = load i32, i32* %85
%100 = call i32 @verbose(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %99)
%101 = bitcast %struct.dvb_frontend_event* %11 to %struct.dvb_frontend_parameters*
br label %102
102: ; preds = %102, %98
%103 = load i32, i32* @tune_service_id.fe_fd
%104 = load i32, i32* @FE_GET_EVENT
%105 = call i64 @ioctl(i32 %103, i32 %104, %struct.dvb_frontend_parameters* %101)
%106 = icmp sgt i64 %105, -1
br i1 %106, label %102, label %107
107: ; preds = %102
%108 = load i64, i64* %76
%109 = load i64, i64* @FE_QPSK
%110 = icmp eq i64 %108, %109
br i1 %110, label %111, label %125
111: ; preds = %107
%112 = load i32, i32* %85
%113 = icmp ult i32 %112, 11700000
%114 = select i1 %113, i32 -9750000, i32 -10600000
%115 = add i32 %114, %112
%116 = xor i1 %113, true
%117 = zext i1 %116 to i32
store i32 %115, i32* %85
%118 = load i32, i32* @tune_service_id.fe_fd
%119 = load i32, i32* %10
%120 = load i8, i8* %9
%121 = call i64 @do_diseqc(i32 %118, i32 %119, i8 signext %120, i32 %117)
%122 = icmp slt i64 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %111
%124 = call i32 @error(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8* %3)
br label %125
125: ; preds = %111, %123, %107
%126 = load i32, i32* @tune_service_id.fe_fd
%127 = load i32, i32* @FE_SET_FRONTEND
%128 = call i64 @ioctl(i32 %126, i32 %127, %struct.dvb_frontend_parameters* %8)
%129 = icmp slt i64 %128, 0
br i1 %129, label %130, label %136
130: ; preds = %125
%131 = load i64, i64* @errno
%132 = call i32 @strerror(i64 %131)
%133 = sext i32 %132 to i64
%134 = inttoptr i64 %133 to i8*
%135 = call i32 (i8*, i8*, ...) @fatal(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0), i8* %134)
br label %136
136: ; preds = %130, %125
%137 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
%138 = bitcast %struct.timeval* %12 to i8*
%139 = bitcast %struct.timeval* %13 to i8*
%140 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%141 = getelementptr inbounds %struct.dvb_frontend_event, %struct.dvb_frontend_event* %11, i64 0, i32 2
%142 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i64 0, i32 0
%143 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i64 0, i32 0
%144 = load i32, i32* %143
br label %145
145: ; preds = %148, %136
%146 = phi i32 [ 0, %136 ], [ %156, %148 ]
%147 = icmp eq i32 %146, 0
br i1 %147, label %148, label %162
148: ; preds = %145
%149 = load i32, i32* @tune_service_id.fe_fd
%150 = load i32, i32* @FE_GET_EVENT
%151 = call i64 @ioctl(i32 %149, i32 %150, %struct.dvb_frontend_parameters* %101)
%152 = icmp sgt i64 %151, -1
%153 = load i32, i32* %141
%154 = load i32, i32* @FE_HAS_LOCK
%155 = and i32 %154, %153
%156 = select i1 %152, i32 %155, i32 0
%157 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%158 = load i32, i32* %142
%159 = sub nsw i32 %158, %144
%160 = icmp sgt i32 %159, 120
br i1 %160, label %161, label %145
161: ; preds = %148
br label %166
162: ; preds = %145
%163 = call i32 (i8*, ...) @vverbose(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
br label %164
164: ; preds = %162, %92
%165 = load i32, i32* @tune_service_id.fe_fd
store i32 %165, i32* %4
br label %166
166: ; preds = %161, %164, %80
%167 = phi i32 [ 1, %164 ], [ 0, %80 ], [ 0, %161 ]
ret i32 %167
}