#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 */
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ SG_DXFER_TO_DEV;
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int udrw_cmd(int, unsigned char *, int, void *, int, int /*<<< orphan*/);
int udrw_write_sector(int fd, void *buf, int len, int sector) {
  unsigned char cmd[16];
  memset(cmd, 0, sizeof(cmd));
  cmd[0] = 0x37;
  cmd[2] = (sector >> 24) & 0xff;
  cmd[3] = (sector >> 16) & 0xff;
  cmd[4] = (sector >> 8) & 0xff;
  cmd[5] = sector & 0xff;
  cmd[7] = (len >> 17) & 0xff;
  cmd[8] = (len >> 9) & 0xff;
  return udrw_cmd(fd, cmd, 10, buf, len, SG_DXFER_TO_DEV);
}


x86 assembly (clang, -O0):
<udrw_write_sector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
movb   $0x37,-0x30(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x18,%eax
and    $0xff,%eax
mov    %al,-0x2e(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x10,%eax
and    $0xff,%eax
mov    %al,-0x2d(%rbp)
mov    -0x18(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x2b(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x11,%eax
and    $0xff,%eax
mov    %al,-0x29(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x9,%eax
and    $0xff,%eax
mov    %al,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%r8d
mov    0x2e48(%rip),%rax
mov    (%rax),%r9d
mov    $0xa,%edx
call   1040 <udrw_cmd@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<udrw_write_sector>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%ebx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%r12d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
movb   $0x37,(%rsp)
mov    %ebx,%eax
shr    $0x18,%eax
mov    %al,0x2(%rsp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x3(%rsp)
mov    %bh,0x4(%rsp)
mov    %bl,0x5(%rsp)
mov    %ebp,%eax
shr    $0x11,%eax
mov    %al,0x7(%rsp)
mov    %ebp,%eax
shr    $0x9,%eax
mov    %al,0x8(%rsp)
mov    0x2e79(%rip),%rax
mov    (%rax),%r9d
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0xa,%edx
mov    %r14,%rcx
mov    %ebp,%r8d
call   1040 <udrw_cmd@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SG_DXFER_TO_DEV = global i32 0
define i32 @udrw_write_sector(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 16)
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
store i8 55, i8* %12
%13 = load i32, i32* %8
%14 = ashr i32 %13, 24
%15 = and i32 %14, 255
%16 = trunc i32 %15 to i8
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 2
store i8 %16, i8* %17
%18 = load i32, i32* %8
%19 = ashr i32 %18, 16
%20 = and i32 %19, 255
%21 = trunc i32 %20 to i8
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 3
store i8 %21, i8* %22
%23 = load i32, i32* %8
%24 = ashr i32 %23, 8
%25 = and i32 %24, 255
%26 = trunc i32 %25 to i8
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 4
store i8 %26, i8* %27
%28 = load i32, i32* %8
%29 = and i32 %28, 255
%30 = trunc i32 %29 to i8
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 5
store i8 %30, i8* %31
%32 = load i32, i32* %7
%33 = ashr i32 %32, 17
%34 = and i32 %33, 255
%35 = trunc i32 %34 to i8
%36 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 7
store i8 %35, i8* %36
%37 = load i32, i32* %7
%38 = ashr i32 %37, 9
%39 = and i32 %38, 255
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 8
store i8 %40, i8* %41
%42 = load i32, i32* %5
%43 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%44 = load i8*, i8** %6
%45 = load i32, i32* %7
%46 = load i32, i32* @SG_DXFER_TO_DEV
%47 = call i32 @udrw_cmd(i32 %42, i8* %43, i32 10, i8* %44, i32 %45, i32 %46)
ret i32 %47
}

LLVM IR (-O2):
@SG_DXFER_TO_DEV = global i32 0
define i32 @udrw_write_sector(i32 %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 0, i32 16)
store i8 55, i8* %6
%8 = lshr i32 %3, 24
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 2
store i8 %9, i8* %10
%11 = lshr i32 %3, 16
%12 = trunc i32 %11 to i8
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 3
store i8 %12, i8* %13
%14 = lshr i32 %3, 8
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 4
store i8 %15, i8* %16
%17 = trunc i32 %3 to i8
%18 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 5
store i8 %17, i8* %18
%19 = lshr i32 %2, 17
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 7
store i8 %20, i8* %21
%22 = lshr i32 %2, 9
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 8
store i8 %23, i8* %24
%25 = load i32, i32* @SG_DXFER_TO_DEV
%26 = call i32 @udrw_cmd(i32 %0, i8* %6, i32 10, i8* %1, i32 %2, i32 %25)
ret i32 %26
}