#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 {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ FE_SET_FRONTEND;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct dvb_frontend_parameters *);
int /*<<< orphan*/ perror(char *);
int FESetFrontend(int fd, struct dvb_frontend_parameters *parameters) {
  int result;
  if (!parameters)
    return -EINVAL;
  if ((result = ioctl(fd, FE_SET_FRONTEND, parameters) < 0)) {
    perror("FE_SET_FRONTEND");
    return result;
  }
  return 0;
}


x86 assembly (clang, -O0):
<FESetFrontend>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114d <FESetFrontend+0x2d>
xor    %eax,%eax
mov    0x2e95(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <FESetFrontend+0x7f>
mov    -0x8(%rbp),%edi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x14(%rbp)
test   $0x1,%al
jne    1181 <FESetFrontend+0x61>
jmp    1198 <FESetFrontend+0x78>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <FESetFrontend+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FESetFrontend>:
push   %rax
test   %rsi,%rsi
je     1143 <FESetFrontend+0x23>
mov    %rsi,%rdx
mov    0x2ec0(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     1150 <FESetFrontend+0x30>
pop    %rcx
ret
mov    0x2e8e(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rcx
ret
lea    0xea9(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.dvb_frontend_parameters = type { i32 }
@EINVAL = global i32 0
@FE_SET_FRONTEND = global i32 0
@.str = [16 x i8] c"FE_SET_FRONTEND\00"
define i32 @FESetFrontend(i32 %0, %struct.dvb_frontend_parameters* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.dvb_frontend_parameters*
%6 = alloca i32
store i32 %0, i32* %4
store %struct.dvb_frontend_parameters* %1, %struct.dvb_frontend_parameters** %5
%7 = load %struct.dvb_frontend_parameters*, %struct.dvb_frontend_parameters** %5
%8 = icmp ne %struct.dvb_frontend_parameters* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i32, i32* @EINVAL
%11 = sub nsw i32 0, %10
store i32 %11, i32* %3
br label %23
12: ; preds = %2
%13 = load i32, i32* %4
%14 = load i32, i32* @FE_SET_FRONTEND
%15 = load %struct.dvb_frontend_parameters*, %struct.dvb_frontend_parameters** %5
%16 = call i64 @ioctl(i32 %13, i32 %14, %struct.dvb_frontend_parameters* %15)
%17 = icmp slt i64 %16, 0
%18 = zext i1 %17 to i32
store i32 %18, i32* %6
br i1 %17, label %19, label %22
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %23
22: ; preds = %12
store i32 0, i32* %3
br label %23
23: ; preds = %22, %19, %9
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.dvb_frontend_parameters = type { i32 }
@EINVAL = global i32 0
@FE_SET_FRONTEND = global i32 0
@.str = [16 x i8] c"FE_SET_FRONTEND\00"
define i32 @FESetFrontend(i32 %0, %struct.dvb_frontend_parameters* %1) {
%3 = icmp eq %struct.dvb_frontend_parameters* %1, null
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @EINVAL
%6 = sub nsw i32 0, %5
br label %13
7: ; preds = %2
%8 = load i32, i32* @FE_SET_FRONTEND
%9 = tail call i64 @ioctl(i32 %0, i32 %8, %struct.dvb_frontend_parameters* %1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %7, %11, %4
%14 = phi i32 [ 1, %11 ], [ %6, %4 ], [ 0, %7 ]
ret i32 %14
}