#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_raw_cmd {
  unsigned char *data;
  int length;
  int rate;
  int flags;
  int *cmd;
  int cmd_count;
  int *reply;
};

/* Variables and functions */
int /*<<< orphan*/ FDRAWCMD;
int FD_RAW_INTR;
int FD_RAW_WRITE;
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct floppy_raw_cmd *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void lif_write_phy_device(int device, int cylinder, int head, int sector,
                          unsigned char *data) {
  struct floppy_raw_cmd cmd;
  cmd.data = data;
  cmd.length = 256;
  cmd.rate = 2;
  cmd.flags = FD_RAW_INTR | FD_RAW_WRITE;
  cmd.cmd[0] = 0x45;
  cmd.cmd[1] = head ? 4 : 0;
  cmd.cmd[2] = cylinder;
  cmd.cmd[3] = head ? 1 : 0;
  cmd.cmd[4] = sector;
  cmd.cmd[5] = 1;
  cmd.cmd[6] = 16;
  cmd.cmd[7] = 32;
  cmd.cmd[8] = 0xFF;
  cmd.cmd_count = 9;
  if ((ioctl(device, FDRAWCMD, &cmd) < 0) || (cmd.reply[0] & 0xC0)) {
    fprintf(stderr, "Error writing cylinder %d, head %d, sector %d\n", cylinder,
            head, sector);
    fprintf(stderr, "error= %s (%d)\n", strerror(errno), errno);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<lif_write_phy_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
movl   $0x100,-0x40(%rbp)
movl   $0x2,-0x3c(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movl   $0x45,(%rax)
mov    -0xc(%rbp),%edx
xor    %ecx,%ecx
mov    $0x4,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0xc(%rbp),%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x10(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,0x10(%rax)
mov    -0x30(%rbp),%rax
movl   $0x1,0x14(%rax)
mov    -0x30(%rbp),%rax
movl   $0x10,0x18(%rax)
mov    -0x30(%rbp),%rax
movl   $0x20,0x1c(%rax)
mov    -0x30(%rbp),%rax
movl   $0xff,0x20(%rax)
movl   $0x9,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jl     1235 <lif_write_phy_device+0xf5>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
and    $0xc0,%eax
cmp    $0x0,%eax
je     1297 <lif_write_phy_device+0x157>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
mov    -0x10(%rbp),%r8d
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
mov    0x2d43(%rip),%rax
mov    (%rax),%ecx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.floppy_raw_cmd = type { i8*, i32, i32, i32, i32*, i32, i32* }
@FD_RAW_INTR = global i32 0
@FD_RAW_WRITE = global i32 0
@FDRAWCMD = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Error writing cylinder %d, head %d, sector %d\0A\00"
@.str.1 = [16 x i8] c"error= %s (%d)\0A\00"
@errno = global i32 0
define void @lif_write_phy_device(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.floppy_raw_cmd
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i8*, i8** %10
%13 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 0
store i8* %12, i8** %13
%14 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 1
store i32 256, i32* %14
%15 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 2
store i32 2, i32* %15
%16 = load i32, i32* @FD_RAW_INTR
%17 = load i32, i32* @FD_RAW_WRITE
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 3
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%21 = load i32*, i32** %20
%22 = getelementptr inbounds i32, i32* %21, i64 0
store i32 69, i32* %22
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 4, i32 0
%27 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 1
store i32 %26, i32* %29
%30 = load i32, i32* %7
%31 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%32 = load i32*, i32** %31
%33 = getelementptr inbounds i32, i32* %32, i64 2
store i32 %30, i32* %33
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
%36 = zext i1 %35 to i64
%37 = select i1 %35, i32 1, i32 0
%38 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%39 = load i32*, i32** %38
%40 = getelementptr inbounds i32, i32* %39, i64 3
store i32 %37, i32* %40
%41 = load i32, i32* %9
%42 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%43 = load i32*, i32** %42
%44 = getelementptr inbounds i32, i32* %43, i64 4
store i32 %41, i32* %44
%45 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%46 = load i32*, i32** %45
%47 = getelementptr inbounds i32, i32* %46, i64 5
store i32 1, i32* %47
%48 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%49 = load i32*, i32** %48
%50 = getelementptr inbounds i32, i32* %49, i64 6
store i32 16, i32* %50
%51 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%52 = load i32*, i32** %51
%53 = getelementptr inbounds i32, i32* %52, i64 7
store i32 32, i32* %53
%54 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 4
%55 = load i32*, i32** %54
%56 = getelementptr inbounds i32, i32* %55, i64 8
store i32 255, i32* %56
%57 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 5
store i32 9, i32* %57
%58 = load i32, i32* %6
%59 = load i32, i32* @FDRAWCMD
%60 = call i64 @ioctl(i32 %58, i32 %59, %struct.floppy_raw_cmd* %11)
%61 = icmp slt i64 %60, 0
br i1 %61, label %69, label %62
62: ; preds = %5
%63 = getelementptr inbounds %struct.floppy_raw_cmd, %struct.floppy_raw_cmd* %11, i32 0, i32 6
%64 = load i32*, i32** %63
%65 = getelementptr inbounds i32, i32* %64, i64 0
%66 = load i32, i32* %65
%67 = and i32 %66, 192
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %81
69: ; preds = %62, %5
%70 = load i32, i32* @stderr
%71 = load i32, i32* %7
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %71, i32 %72, i32 %73)
%75 = load i32, i32* @stderr
%76 = load i32, i32* @errno
%77 = call i8* @strerror(i32 %76)
%78 = load i32, i32* @errno
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %77, i32 %78)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %62
ret void
}

LLVM IR (-O2):