#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 */
struct dvb_frontend_parameters {
  scalar_t__ type;
};
struct dvb_frontend_info {
  scalar_t__ type;
};

/* Variables and functions */
int /*<<< orphan*/ FE_GET_INFO;
scalar_t__ FE_OFDM;
int /*<<< orphan*/ FE_SET_FRONTEND;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dvb_frontend_parameters *);
int setup_frontend(int fe_fd, struct dvb_frontend_parameters *frontend) {
  struct dvb_frontend_info fe_info;
  if (ioctl(fe_fd, FE_GET_INFO, &fe_info) < 0)
    return -1;
  if (fe_info.type != FE_OFDM)
    return -1;
  if (ioctl(fe_fd, FE_SET_FRONTEND, frontend) < 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<setup_frontend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eb7(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    114a <setup_frontend+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <setup_frontend+0x8c>
mov    -0x18(%rbp),%rax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%rax
je     116a <setup_frontend+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <setup_frontend+0x8c>
mov    -0x8(%rbp),%edi
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1195 <setup_frontend+0x85>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <setup_frontend+0x8c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_frontend>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ec1(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
js     115d <setup_frontend+0x4d>
mov    (%rsp),%rcx
mov    0x2e97(%rip),%rdx
cmp    (%rdx),%rcx
jne    115d <setup_frontend+0x4d>
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
sar    $0x3f,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dvb_frontend_parameters = type { i64 }
%struct.dvb_frontend_info = type { i64 }
@FE_GET_INFO = global i32 0
@FE_OFDM = global i64 0
@FE_SET_FRONTEND = global i32 0
define i32 @setup_frontend(i32 %0, %struct.dvb_frontend_parameters* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.dvb_frontend_parameters*
%6 = alloca %struct.dvb_frontend_info
store i32 %0, i32* %4
store %struct.dvb_frontend_parameters* %1, %struct.dvb_frontend_parameters** %5
%7 = load i32, i32* %4
%8 = load i32, i32* @FE_GET_INFO
%9 = bitcast %struct.dvb_frontend_info* %6 to %struct.dvb_frontend_parameters*
%10 = call i64 @ioctl(i32 %7, i32 %8, %struct.dvb_frontend_parameters* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %27
13: ; preds = %2
%14 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %6, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @FE_OFDM
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %3
br label %27
19: ; preds = %13
%20 = load i32, i32* %4
%21 = load i32, i32* @FE_SET_FRONTEND
%22 = load %struct.dvb_frontend_parameters*, %struct.dvb_frontend_parameters** %5
%23 = call i64 @ioctl(i32 %20, i32 %21, %struct.dvb_frontend_parameters* %22)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store i32 -1, i32* %3
br label %27
26: ; preds = %19
store i32 0, i32* %3
br label %27
27: ; preds = %26, %25, %18, %12
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.dvb_frontend_parameters = type { i64 }
%struct.dvb_frontend_info = type { i64 }
@FE_GET_INFO = global i32 0
@FE_OFDM = global i64 0
@FE_SET_FRONTEND = global i32 0
define i32 @setup_frontend(i32 %0, %struct.dvb_frontend_parameters* %1) {
%3 = alloca %struct.dvb_frontend_info
%4 = bitcast %struct.dvb_frontend_info* %3 to i8*
%5 = load i32, i32* @FE_GET_INFO
%6 = bitcast %struct.dvb_frontend_info* %3 to %struct.dvb_frontend_parameters*
%7 = call i64 @ioctl(i32 %0, i32 %5, %struct.dvb_frontend_parameters* %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %2
%10 = getelementptr inbounds %struct.dvb_frontend_info, %struct.dvb_frontend_info* %3, i64 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @FE_OFDM
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %19
14: ; preds = %9
%15 = load i32, i32* @FE_SET_FRONTEND
%16 = call i64 @ioctl(i32 %0, i32 %15, %struct.dvb_frontend_parameters* %1)
%17 = ashr i64 %16, 63
%18 = trunc i64 %17 to i32
br label %19
19: ; preds = %14, %9, %2
%20 = phi i32 [ -1, %2 ], [ -1, %9 ], [ %18, %14 ]
ret i32 %20
}