#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
void trd_put_data(char *img, char *buf, int trk, int sec, int len, int dt) {
  if ((dt == 0x18) || (dt == 0x19)) {
    sec = (trk << 5) | (sec & 0x0f);
    char *ptr = buf;
    while (len > 0) {
      memcpy(img + (sec << 8), ptr, 0x100);
      sec++;
      if ((sec & 0x0f) == 0)
        sec += 0x10;
      ptr += 0x100;
      len--;
    }
  } else {
    sec = (trk << 4) | (sec & 0x0f);
    memcpy(img + (sec << 8), buf, len << 8);
  }
}


x86 assembly (clang, -O0):
<trd_put_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
cmpl   $0x18,-0x20(%rbp)
je     1142 <trd_put_data+0x32>
cmpl   $0x19,-0x20(%rbp)
jne    11c4 <trd_put_data+0xb4>
mov    -0x14(%rbp),%eax
shl    $0x5,%eax
mov    -0x18(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11bf <trd_put_data+0xaf>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
cltq
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    11a3 <trd_put_data+0x93>
mov    -0x18(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    115b <trd_put_data+0x4b>
jmp    11f3 <trd_put_data+0xe3>
mov    -0x14(%rbp),%eax
shl    $0x4,%eax
mov    -0x18(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%eax
shl    $0x8,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
shl    $0x8,%edx
call   1030 <memcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trd_put_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
and    $0xfffffffe,%r9d
cmp    $0x18,%r9d
jne    117f <trd_put_data+0x6f>
test   %r15d,%r15d
jle    1174 <trd_put_data+0x64>
and    $0xf,%ecx
shl    $0x5,%ebp
or     %ecx,%ebp
add    $0x1,%r15d
nopl   (%rax)
mov    %ebp,%eax
shl    $0x8,%eax
movslq %eax,%rdi
add    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
lea    0x1(%rbp),%eax
add    $0x11,%ebp
test   $0xf,%al
cmovne %eax,%ebp
add    $0x100,%rbx
add    $0xffffffff,%r15d
cmp    $0x1,%r15d
ja     1140 <trd_put_data+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
shl    $0xc,%ebp
and    $0xf,%ecx
shl    $0x8,%ecx
or     %ebp,%ecx
movslq %ecx,%rax
add    %rax,%r14
shl    $0x8,%r15d
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <memcpy@plt>

LLVM IR (-O0):
define void @trd_put_data(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i32, i32* %12
%15 = icmp eq i32 %14, 24
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = load i32, i32* %12
%18 = icmp eq i32 %17, 25
br i1 %18, label %19, label %51
19: ; preds = %16, %6
%20 = load i32, i32* %9
%21 = shl i32 %20, 5
%22 = load i32, i32* %10
%23 = and i32 %22, 15
%24 = or i32 %21, %23
store i32 %24, i32* %10
%25 = load i8*, i8** %8
store i8* %25, i8** %13
br label %26
26: ; preds = %45, %19
%27 = load i32, i32* %11
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %50
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = load i32, i32* %10
%32 = shl i32 %31, 8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8*, i8** %13
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 256)
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = load i32, i32* %10
%40 = and i32 %39, 15
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %29
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 16
store i32 %44, i32* %10
br label %45
45: ; preds = %42, %29
%46 = load i8*, i8** %13
%47 = getelementptr inbounds i8, i8* %46, i64 256
store i8* %47, i8** %13
%48 = load i32, i32* %11
%49 = add nsw i32 %48, -1
store i32 %49, i32* %11
br label %26
50: ; preds = %26
br label %66
51: ; preds = %16
%52 = load i32, i32* %9
%53 = shl i32 %52, 4
%54 = load i32, i32* %10
%55 = and i32 %54, 15
%56 = or i32 %53, %55
store i32 %56, i32* %10
%57 = load i8*, i8** %7
%58 = load i32, i32* %10
%59 = shl i32 %58, 8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %57, i64 %60
%62 = load i8*, i8** %8
%63 = load i32, i32* %11
%64 = shl i32 %63, 8
%65 = call i32 @memcpy(i8* %61, i8* %62, i32 %64)
br label %66
66: ; preds = %51, %50
ret void
}

LLVM IR (-O2):
define void @trd_put_data(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = and i32 %5, -2
%8 = icmp eq i32 %7, 24
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = icmp sgt i32 %4, 0
br i1 %10, label %11, label %40
11: ; preds = %9
%12 = and i32 %3, 15
%13 = shl i32 %2, 5
%14 = or i32 %12, %13
br label %15
15: ; preds = %11, %15
%16 = phi i8* [ %28, %15 ], [ %1, %11 ]
%17 = phi i32 [ %27, %15 ], [ %14, %11 ]
%18 = phi i32 [ %29, %15 ], [ %4, %11 ]
%19 = shl i32 %17, 8
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
%22 = tail call i32 @memcpy(i8* %21, i8* %16, i32 256)
%23 = add nsw i32 %17, 1
%24 = and i32 %23, 15
%25 = icmp eq i32 %24, 0
%26 = add nsw i32 %17, 17
%27 = select i1 %25, i32 %26, i32 %23
%28 = getelementptr inbounds i8, i8* %16, i64 256
%29 = add nsw i32 %18, -1
%30 = icmp ugt i32 %18, 1
br i1 %30, label %15, label %40
31: ; preds = %6
%32 = shl i32 %2, 12
%33 = shl i32 %3, 8
%34 = and i32 %33, 3840
%35 = or i32 %34, %32
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = shl i32 %4, 8
%39 = tail call i32 @memcpy(i8* %37, i8* %1, i32 %38)
br label %40
40: ; preds = %15, %9, %31
ret void
}