#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 */
scalar_t__ FE_ATSC;
int /*<<< orphan*/ FE_GET_INFO;
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 -10;
  if (fe_info.type != FE_ATSC)
    return -11;
  if (ioctl(fe_fd, FE_SET_FRONTEND, frontend) < 0)
    return -12;
  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   $0xfffffff6,-0x4(%rbp)
jmp    119c <setup_frontend+0x8c>
mov    -0x18(%rbp),%rax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%rax
je     116a <setup_frontend+0x5a>
movl   $0xfffffff5,-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   $0xfffffff4,-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>
test   %rax,%rax
js     115f <setup_frontend+0x4f>
mov    (%rsp),%rcx
mov    0x2e97(%rip),%rdx
mov    $0xfffffff5,%eax
cmp    (%rdx),%rcx
jne    1164 <setup_frontend+0x54>
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %rbx,%rdx
call   1030 <ioctl@plt>
sar    $0x3f,%rax
and    $0xfffffff4,%eax
jmp    1164 <setup_frontend+0x54>
mov    $0xfffffff6,%eax
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_ATSC = 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 -10, 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_ATSC
%17 = icmp ne i64 %15, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -11, 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 -12, 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_ATSC = 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_ATSC
%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 = icmp slt i64 %16, 0
%18 = select i1 %17, i32 -12, i32 0
br label %19
19: ; preds = %14, %9, %2
%20 = phi i32 [ -10, %2 ], [ -11, %9 ], [ %18, %14 ]
ret i32 %20
}