#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*/ value;
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ emu_file_write(int, int *, int);
void emu_file_write_track_bits(int fd, uint32_t *words, int num_words, int cyl,
                               int head, uint32_t track_bytes) {
  uint32_t value;
  int i;
  if (fd != -1) {
    value = 0x12345678;
    emu_file_write(fd, &value, sizeof(value));
    value = cyl;
    emu_file_write(fd, &value, sizeof(value));
    value = head;
    emu_file_write(fd, &value, sizeof(value));
    if (cyl != -1) {
      uint32_t fill;
      if (num_words == 0 || words[num_words - 1] & 1) {
        fill = 0x55555555;
      } else {
        fill = 0xaaaaaaaa;
      }
      for (i = num_words; i < track_bytes / 4; i++) {
        words[i] = fill;
      }
      emu_file_write(fd, words, track_bytes);
    }
  }
}


x86 assembly (clang, -O0):
<emu_file_write_track_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
je     1214 <emu_file_write_track_bits+0x104>
movl   $0x12345678,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <emu_file_write@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <emu_file_write@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1030 <emu_file_write@plt>
cmpl   $0xffffffff,-0x18(%rbp)
je     120f <emu_file_write_track_bits+0xff>
cmpl   $0x0,-0x14(%rbp)
je     11ad <emu_file_write_track_bits+0x9d>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11b9 <emu_file_write_track_bits+0xa9>
movl   $0x55555555,-0x2c(%rbp)
jmp    11c0 <emu_file_write_track_bits+0xb0>
movl   $0xaaaaaaaa,-0x2c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jge    1200 <emu_file_write_track_bits+0xf0>
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c6 <emu_file_write_track_bits+0xb6>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <emu_file_write@plt>
jmp    1214 <emu_file_write_track_bits+0x104>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emu_file_write_track_bits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0xffffffff,%edi
je     1298 <emu_file_write_track_bits+0x188>
mov    %r8d,%r13d
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %rsi,%r15
movl   $0x12345678,0x4(%rsp)
12
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
mov    %r9,%rbx
mov    %edi,%r12d
call   1030 <emu_file_write@plt>
mov    %ebp,0x4(%rsp)
mov    %r12d,%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <emu_file_write@plt>
mov    %r13d,0x4(%rsp)
mov    %r12d,%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1030 <emu_file_write@plt>
cmp    $0xffffffff,%ebp
je     1298 <emu_file_write_track_bits+0x188>
mov    %rbx,%rdx
movslq %r14d,%rax
test   %r14d,%r14d
je     11a4 <emu_file_write_track_bits+0x94>
testb  $0x1,-0x4(%r15,%rax,4)
mov    $0xaaaaaaaa,%esi
mov    $0x55555555,%r11d
cmove  %esi,%r11d
jmp    11aa <emu_file_write_track_bits+0x9a>
mov    $0x55555555,%r11d
lea    0x3(%rdx),%esi
test   %edx,%edx
cmovns %edx,%esi
sar    $0x2,%esi
cmp    %r14d,%esi
jle    128d <emu_file_write_track_bits+0x17d>
movslq %esi,%rbx
mov    %rbx,%r9
sub    %rax,%r9
cmp    $0x8,%r9
jb     1280 <emu_file_write_track_bits+0x170>
mov    %r9,%r8
and    $0xfffffffffffffff8,%r8
movd   %r11d,%xmm0
pshufd $0x0,%xmm0,%xmm0
lea    -0x8(%r8),%rsi
mov    %rsi,%rbp
shr    $0x3,%rbp
add    $0x1,%rbp
mov    %ebp,%r10d
and    $0x3,%r10d
cmp    $0x18,%rsi
jae    1202 <emu_file_write_track_bits+0xf2>
xor    %esi,%esi
jmp    1249 <emu_file_write_track_bits+0x139>
and    $0xfffffffffffffffc,%rbp
lea    (%r15,%rax,4),%rcx
add    $0x70,%rcx
xor    %esi,%esi
movdqu %xmm0,-0x70(%rcx,%rsi,4)
movdqu %xmm0,-0x60(%rcx,%rsi,4)
movdqu %xmm0,-0x50(%rcx,%rsi,4)
movdqu %xmm0,-0x40(%rcx,%rsi,4)
movdqu %xmm0,-0x30(%rcx,%rsi,4)
movdqu %xmm0,-0x20(%rcx,%rsi,4)
movdqu %xmm0,-0x10(%rcx,%rsi,4)
movdqu %xmm0,(%rcx,%rsi,4)
add    $0x20,%rsi
add    $0xfffffffffffffffc,%rbp
jne    1210 <emu_file_write_track_bits+0x100>
test   %r10,%r10
je     1274 <emu_file_write_track_bits+0x164>
add    %rax,%rsi
lea    (%r15,%rsi,4),%rsi
add    $0x10,%rsi
shl    $0x5,%r10
xor    %ecx,%ecx
nop
movdqu %xmm0,-0x10(%rsi,%rcx,1)
movdqu %xmm0,(%rsi,%rcx,1)
add    $0x20,%rcx
cmp    %rcx,%r10
jne    1260 <emu_file_write_track_bits+0x150>
cmp    %r8,%r9
je     128d <emu_file_write_track_bits+0x17d>
add    %r8,%rax
nopl   0x0(%rax)
mov    %r11d,(%r15,%rax,4)
add    $0x1,%rax
cmp    %rax,%rbx
jne    1280 <emu_file_write_track_bits+0x170>
mov    %r12d,%edi
mov    %r15,%rsi
call   1030 <emu_file_write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @emu_file_write_track_bits(i32 %0, i32* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = bitcast i32* %7 to i8*
%9 = icmp eq i32 %0, -1
br i1 %9, label %102, label %10
10: ; preds = %6
store i32 305419896, i32* %7
%11 = call i32 @emu_file_write(i32 %0, i32* %7, i32 4)
store i32 %3, i32* %7
%12 = call i32 @emu_file_write(i32 %0, i32* %7, i32 4)
store i32 %4, i32* %7
%13 = call i32 @emu_file_write(i32 %0, i32* %7, i32 4)
%14 = icmp eq i32 %3, -1
br i1 %14, label %102, label %15
15: ; preds = %10
%16 = icmp eq i32 %2, 0
br i1 %16, label %25, label %17
17: ; preds = %15
%18 = add nsw i32 %2, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
%22 = and i32 %21, 1
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i32 -1431655766, i32 1431655765
br label %25
25: ; preds = %17, %15
%26 = phi i32 [ 1431655765, %15 ], [ %24, %17 ]
%27 = sdiv i32 %5, 4
%28 = icmp sgt i32 %27, %2
br i1 %28, label %29, label %100
29: ; preds = %25
%30 = sext i32 %2 to i64
%31 = sext i32 %27 to i64
%32 = sub nsw i64 %31, %30
%33 = icmp ult i64 %32, 8
br i1 %33, label %93, label %34
34: ; preds = %29
%35 = and i64 %32, -8
%36 = add nsw i64 %35, %30
%37 = insertelement <4 x i32> poison, i32 %26, i64 0
%38 = shufflevector <4 x i32> %37, <4 x i32> poison, <4 x i32> zeroinitializer
%39 = insertelement <4 x i32> poison, i32 %26, i64 0
%40 = shufflevector <4 x i32> %39, <4 x i32> poison, <4 x i32> zeroinitializer
%41 = add nsw i64 %35, -8
%42 = lshr exact i64 %41, 3
%43 = add nuw nsw i64 %42, 1
%44 = and i64 %43, 3
%45 = icmp ult i64 %41, 24
br i1 %45, label %77, label %46
46: ; preds = %34
%47 = and i64 %43, 4611686018427387900
br label %48
48: ; preds = %48, %46
%49 = phi i64 [ 0, %46 ], [ %74, %48 ]
%50 = phi i64 [ 0, %46 ], [ %75, %48 ]
%51 = add i64 %49, %30
%52 = getelementptr inbounds i32, i32* %1, i64 %51
%53 = bitcast i32* %52 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %53
%54 = getelementptr inbounds i32, i32* %52, i64 4
%55 = bitcast i32* %54 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %55
%56 = or i64 %49, 8
%57 = add i64 %56, %30
%58 = getelementptr inbounds i32, i32* %1, i64 %57
%59 = bitcast i32* %58 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %59
%60 = getelementptr inbounds i32, i32* %58, i64 4
%61 = bitcast i32* %60 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %61
%62 = or i64 %49, 16
%63 = add i64 %62, %30
%64 = getelementptr inbounds i32, i32* %1, i64 %63
%65 = bitcast i32* %64 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %65
%66 = getelementptr inbounds i32, i32* %64, i64 4
%67 = bitcast i32* %66 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %67
%68 = or i64 %49, 24
%69 = add i64 %68, %30
%70 = getelementptr inbounds i32, i32* %1, i64 %69
%71 = bitcast i32* %70 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %71
%72 = getelementptr inbounds i32, i32* %70, i64 4
%73 = bitcast i32* %72 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %73
%74 = add nuw i64 %49, 32
%75 = add i64 %50, 4
%76 = icmp eq i64 %75, %47
br i1 %76, label %77, label %48
77: ; preds = %48, %34
%78 = phi i64 [ 0, %34 ], [ %74, %48 ]
%79 = icmp eq i64 %44, 0
br i1 %79, label %91, label %80
80: ; preds = %77, %80
%81 = phi i64 [ %88, %80 ], [ %78, %77 ]
%82 = phi i64 [ %89, %80 ], [ 0, %77 ]
%83 = add i64 %81, %30
%84 = getelementptr inbounds i32, i32* %1, i64 %83
%85 = bitcast i32* %84 to <4 x i32>*
store <4 x i32> %38, <4 x i32>* %85
%86 = getelementptr inbounds i32, i32* %84, i64 4
%87 = bitcast i32* %86 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %87
%88 = add nuw i64 %81, 8
%89 = add i64 %82, 1
%90 = icmp eq i64 %89, %44
br i1 %90, label %91, label %80
91: ; preds = %80, %77
%92 = icmp eq i64 %32, %35
br i1 %92, label %100, label %93
93: ; preds = %29, %91
%94 = phi i64 [ %30, %29 ], [ %36, %91 ]
br label %95
95: ; preds = %93, %95
%96 = phi i64 [ %98, %95 ], [ %94, %93 ]
%97 = getelementptr inbounds i32, i32* %1, i64 %96
store i32 %26, i32* %97
%98 = add nsw i64 %96, 1
%99 = icmp eq i64 %98, %31
br i1 %99, label %100, label %95
100: ; preds = %95, %91, %25
%101 = call i32 @emu_file_write(i32 %0, i32* %1, i32 %5)
br label %102
102: ; preds = %10, %100, %6
ret void
}