#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 floppy_struct {
  int size;
  int sect;
  int head;
  int track;
  int rate;
  int cmd_count;
  scalar_t__ *cmd;
  int /*<<< orphan*/ flags;
  scalar_t__ length;
  int /*<<< orphan*/ *data;
  scalar_t__ stretch;
};
struct floppy_raw_cmd {
  int size;
  int sect;
  int head;
  int track;
  int rate;
  int cmd_count;
  scalar_t__ *cmd;
  int /*<<< orphan*/ flags;
  scalar_t__ length;
  int /*<<< orphan*/ *data;
  scalar_t__ stretch;
};

/* Variables and functions */
int /*<<< orphan*/ FDCLRPRM;
int /*<<< orphan*/ FDRAWCMD;
int /*<<< orphan*/ FDSETPRM;
int /*<<< orphan*/ FD_RAW_INTR;
scalar_t__ FD_RECALIBRATE;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct floppy_struct *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void lif_recalibrate_phy_device(int device) {
  struct floppy_raw_cmd cmd;
  struct floppy_struct floppy;
  if (ioctl(device, FDCLRPRM, NULL) < 0) {
    fprintf(stderr, "Error on resetting floppy parameters\n");
    fprintf(stderr, "error= %s (%d)\n", strerror(errno), errno);
    exit(1);
  }
  floppy.size = 2464;
  floppy.sect = 16;
  floppy.head = 2;
  floppy.track = 77;
  floppy.stretch = 0;
  if (ioctl(device, FDSETPRM, &floppy) < 0) {
    fprintf(stderr, "Error on configuring floppy parameters\n");
    fprintf(stderr, "error= %s (%d)\n", strerror(errno), errno);
    exit(1);
  }
  cmd.data = NULL;
  cmd.length = 0;
  cmd.rate = 2;
  cmd.flags = FD_RAW_INTR;
  cmd.cmd[0] = FD_RECALIBRATE;
  cmd.cmd[1] = 0;
  cmd.cmd_count = 2;
  if (ioctl(device, FDRAWCMD, &cmd) < 0) {
    fprintf(stderr, "Error on recalibrate\n");
    fprintf(stderr, "error= %s (%d)\n", strerror(errno), errno);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<lif_recalibrate_phy_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11cb <lif_recalibrate_phy_device+0x8b>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    %rax,%rdx
mov    0x2dff(%rip),%rax
mov    (%rax),%ecx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x9a0,-0x88(%rbp)
movl   $0x10,-0x84(%rbp)
movl   $0x2,-0x80(%rbp)
movl   $0x4d,-0x7c(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    -0x88(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1275 <lif_recalibrate_phy_device+0x135>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x90(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x90(%rbp),%edi
mov    %rax,%rdx
mov    0x2d55(%rip),%rax
mov    (%rax),%ecx
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x2,-0x38(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d51(%rip),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,0x8(%rax)
movl   $0x2,-0x34(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d02(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1339 <lif_recalibrate_phy_device+0x1f9>
mov    0x2cde(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2cc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
mov    0x2c91(%rip),%rax
mov    (%rax),%ecx
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lif_recalibrate_phy_device>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
jns    1170 <lif_recalibrate_phy_device+0x30>
mov    0x2e73(%rip),%rbx
mov    (%rbx),%edi
lea    0xea2(%rip),%rsi
jmp    11a7 <lif_recalibrate_phy_device+0x67>
movaps 0xe89(%rip),%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x38(%rsp)
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    0x2e3a(%rip),%rbx
mov    (%rbx),%edi
lea    0xe9f(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%rbx),%ebx
mov    0x2e11(%rip),%r14
mov    (%r14),%edi
call   1060 <strerror@plt>
mov    (%r14),%ecx
lea    0xe6d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.floppy_raw_cmd = type { i32, i32, i32, i32, i32, i32, i64*, i32, i64, i32*, i64 }
%struct.floppy_struct = type { i32, i32, i32, i32, i32, i32, i64*, i32, i64, i32*, i64 }
@FDCLRPRM = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Error on resetting floppy parameters\0A\00"
@.str.1 = [16 x i8] c"error= %s (%d)\0A\00"
@errno = global i32 0
@FDSETPRM = global i32 0
@.str.2 = [40 x i8] c"Error on configuring floppy parameters\0A\00"
@FD_RAW_INTR = global i32 0
@FD_RECALIBRATE = global i64 0
@FDRAWCMD = global i32 0
@.str.3 = [22 x i8] c"Error on recalibrate\0A\00"
define void @lif_recalibrate_phy_device(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.floppy_raw_cmd
%4 = alloca %struct.floppy_struct
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @FDCLRPRM
%7 = call i64 @ioctl(i32 %5, i32 %6, %struct.floppy_struct* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = load i32, i32* @errno
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %4, i32 0, i32 0
store i32 2464, i32* %19
%20 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %4, i32 0, i32 1
store i32 16, i32* %20
%21 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %4, i32 0, i32 2
store i32 2, i32* %21
%22 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %4, i32 0, i32 3
store i32 77, i32* %22
%23 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %4, i32 0, i32 10
store i64 0, i64* %23
%24 = load i32, i32* %2
%25 = load i32, i32* @FDSETPRM
%26 = call i64 @ioctl(i32 %24, i32 %25, %struct.floppy_struct* %4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = load i32, i32* @errno
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %18
%38 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 9
store i32* null, i32** %38
%39 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 8
store i64 0, i64* %39
%40 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 4
store i32 2, i32* %40
%41 = load i32, i32* @FD_RAW_INTR
%42 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 7
store i32 %41, i32* %42
%43 = load i64, i64* @FD_RECALIBRATE
%44 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 6
%45 = load i64*, i64** %44
%46 = getelementptr inbounds i64, i64* %45, i64 0
store i64 %43, i64* %46
%47 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 6
%48 = load i64*, i64** %47
%49 = getelementptr inbounds i64, i64* %48, i64 1
store i64 0, i64* %49
%50 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %3, i32 0, i32 5
store i32 2, i32* %50
%51 = load i32, i32* %2
%52 = load i32, i32* @FDRAWCMD
%53 = bitcast %struct.floppy_raw_cmd* %3 to %struct.floppy_struct*
%54 = call i64 @ioctl(i32 %51, i32 %52, %struct.floppy_struct* %53)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %65
56: ; preds = %37
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = load i32, i32* @errno
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %61, i32 %62)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %37
ret void
}

LLVM IR (-O2):
%struct.floppy_struct = type { i32, i32, i32, i32, i32, i32, i64*, i32, i64, i32*, i64 }
@FDCLRPRM = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Error on resetting floppy parameters\0A\00"
@.str.1 = [16 x i8] c"error= %s (%d)\0A\00"
@errno = global i32 0
@FDSETPRM = global i32 0
@.str.2 = [40 x i8] c"Error on configuring floppy parameters\0A\00"
@FD_RAW_INTR = global i32 0
@FD_RECALIBRATE = global i64 0
@FDRAWCMD = global i32 0
define void @lif_recalibrate_phy_device(i32 %0) {
%2 = alloca %struct.floppy_struct
%3 = bitcast %struct.floppy_struct* %2 to i8*
%4 = load i32, i32* @FDCLRPRM
%5 = tail call i64 @ioctl(i32 %0, i32 %4, %struct.floppy_struct* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = load i32, i32* @errno
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %1
%17 = bitcast %struct.floppy_struct* %2 to <4 x i32>*
store <4 x i32> <i32 2464, i32 16, i32 2, i32 77>, <4 x i32>* %17
%18 = getelementptr inbounds %struct.floppy_struct, %struct.floppy_struct* %2, i64 0, i32 10
store i64 0, i64* %18
%19 = load i32, i32* @FDSETPRM
%20 = call i64 @ioctl(i32 %0, i32 %19, %struct.floppy_struct* %2)
%21 = icmp slt i64 %20, 0
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = load i32, i32* @errno
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27)
%29 = call i32 @exit(i32 1)
unreachable
}