#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  unsigned int symbol_rate;
  int /*<<< orphan*/ fec_inner;
};
struct TYPE_4__ {
  TYPE_1__ qpsk;
};
struct dvb_frontend_parameters {
  unsigned int frequency;
  TYPE_2__ u;
  int /*<<< orphan*/ inversion;
};
struct dvb_frontend_event {
  unsigned int frequency;
  TYPE_2__ u;
  int /*<<< orphan*/ inversion;
};

/* Variables and functions */
int /*<<< orphan*/ FEC_AUTO;
int /*<<< orphan*/ FE_GET_EVENT;
int /*<<< orphan*/ FE_SET_FRONTEND;
int /*<<< orphan*/ INVERSION_AUTO;
int ioctl(int, int /*<<< orphan*/, struct dvb_frontend_parameters *);
int /*<<< orphan*/ perror(char *);
int do_tune(int fefd, unsigned int ifreq, unsigned int sr) {
  struct dvb_frontend_parameters tuneto;
  struct dvb_frontend_event ev;
  while (1) {
    if (ioctl(fefd, FE_GET_EVENT, &ev) == -1)
      break;
  }
  tuneto.frequency = ifreq;
  tuneto.inversion = INVERSION_AUTO;
  tuneto.u.qpsk.symbol_rate = sr;
  tuneto.u.qpsk.fec_inner = FEC_AUTO;
  if (ioctl(fefd, FE_SET_FRONTEND, &tuneto) == -1) {
    perror("FE_SET_FRONTEND failed");
    return (1 == 0);
  }
  return (1 == 1);
}


x86 assembly (clang, -O0):
<do_tune>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1154 <do_tune+0x34>
jmp    1159 <do_tune+0x39>
jmp    1131 <do_tune+0x11>
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11b3 <do_tune+0x93>
lea    0xe5e(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ba <do_tune+0x9a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_tune>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edx,%r14d
mov    %esi,%r15d
mov    %edi,%ebx
mov    0x2e8d(%rip),%r12
lea    0x10(%rsp),%rbp
mov    (%r12),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1140 <do_tune+0x20>
mov    %r15d,(%rsp)
mov    0x2e92(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
mov    %r14d,0x4(%rsp)
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0xffffffff,%ecx
je     11a2 <do_tune+0x82>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe57(%rip),%rdi
call   1040 <perror@plt>
xor    %eax,%eax
jmp    1195 <do_tune+0x75>

LLVM IR (-O0):
%struct.dvb_frontend_parameters = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.dvb_frontend_event = type { i32, %struct.TYPE_4__, i32 }
@FE_GET_EVENT = global i32 0
@INVERSION_AUTO = global i32 0
@FEC_AUTO = global i32 0
@FE_SET_FRONTEND = global i32 0
@.str = [23 x i8] c"FE_SET_FRONTEND failed\00"
define i32 @do_tune(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.dvb_frontend_parameters
%9 = alloca %struct.dvb_frontend_event
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
br label %10
10: ; preds = %3, %17
%11 = load i32, i32* %5
%12 = load i32, i32* @FE_GET_EVENT
%13 = bitcast %struct.dvb_frontend_event* %9 to %struct.dvb_frontend_parameters*
%14 = call i32 @ioctl(i32 %11, i32 %12, %struct.dvb_frontend_parameters* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %10
br label %18
17: ; preds = %10
br label %10
18: ; preds = %16
%19 = load i32, i32* %6
%20 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %8, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @INVERSION_AUTO
%22 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %8, i32 0, i32 2
store i32 %21, i32* %22
%23 = load i32, i32* %7
%24 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %8, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %24, i32 0, i32 0
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 0
store i32 %23, i32* %26
%27 = load i32, i32* @FEC_AUTO
%28 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %8, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 0
%30 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %29, i32 0, i32 1
store i32 %27, i32* %30
%31 = load i32, i32* %5
%32 = load i32, i32* @FE_SET_FRONTEND
%33 = call i32 @ioctl(i32 %31, i32 %32, %struct.dvb_frontend_parameters* %8)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %18
%36 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %38
37: ; preds = %18
store i32 1, i32* %4
br label %38
38: ; preds = %37, %35
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
%struct.dvb_frontend_parameters = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32 }
%struct.dvb_frontend_event = type { i32, %struct.TYPE_4__, i32 }
@FE_GET_EVENT = global i32 0
@INVERSION_AUTO = global i32 0
@FEC_AUTO = global i32 0
@FE_SET_FRONTEND = global i32 0
@.str = [23 x i8] c"FE_SET_FRONTEND failed\00"
define i32 @do_tune(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.dvb_frontend_parameters
%5 = alloca %struct.dvb_frontend_event
%6 = bitcast %struct.dvb_frontend_parameters* %4 to i8*
%7 = bitcast %struct.dvb_frontend_event* %5 to i8*
%8 = bitcast %struct.dvb_frontend_event* %5 to %struct.dvb_frontend_parameters*
br label %9
9: ; preds = %9, %3
%10 = load i32, i32* @FE_GET_EVENT
%11 = call i32 @ioctl(i32 %0, i32 %10, %struct.dvb_frontend_parameters* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %4, i64 0, i32 0
store i32 %1, i32* %14
%15 = load i32, i32* @INVERSION_AUTO
%16 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %4, i64 0, i32 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %4, i64 0, i32 1, i32 0, i32 0
store i32 %2, i32* %17
%18 = load i32, i32* @FEC_AUTO
%19 = getelementptr inbounds %struct.dvb_frontend_parameters, %struct.dvb_frontend_parameters* %4, i64 0, i32 1, i32 0, i32 1
store i32 %18, i32* %19
%20 = load i32, i32* @FE_SET_FRONTEND
%21 = call i32 @ioctl(i32 %0, i32 %20, %struct.dvb_frontend_parameters* %4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %13, %23
%26 = phi i32 [ 0, %23 ], [ 1, %13 ]
ret i32 %26
}