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

/* Variables and functions */
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int sio_write_disk_header(FILE *fp, int num_sectors, int disk_type, int wp) {
  int i;
  rewind(fp);
  fputc(0x96, fp);
  fputc(0x02, fp);
  switch (disk_type) {
  case 0x01:
    break;
  case 0x02:
    num_sectors -= 3;
    num_sectors <<= 1;
    num_sectors += 3;
    num_sectors |= 1;
    break;
  case 0x03:
  case 0x04:
    num_sectors <<= 1;
    break;
  default:
    break;
  }
  num_sectors <<= 3;
  fputc(num_sectors & 0xff, fp);
  fputc((num_sectors >> 8) & 0xff, fp);
  if (disk_type == 0x01) {
    fputc(128, fp);
    fputc(0, fp);
  } else {
    fputc(0, fp);
    fputc(1, fp);
  }
  fputc((num_sectors >> 16) & 0xff, fp);
  fputc((num_sectors >> 24) & 0xff, fp);
  for (i = 8; i < 15; ++i)
    fputc(0, fp);
  fputc(wp, fp);
  return 0;
}


x86 assembly (clang, -O0):
<sio_write_disk_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x8(%rbp),%rsi
mov    $0x96,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x2,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x1,%eax
je     1193 <sio_write_disk_header+0x73>
jmp    116e <sio_write_disk_header+0x4e>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     1198 <sio_write_disk_header+0x78>
jmp    117f <sio_write_disk_header+0x5f>
mov    -0x1c(%rbp),%eax
add    $0xfffffffd,%eax
sub    $0x2,%eax
jb     11c1 <sio_write_disk_header+0xa1>
jmp    11cf <sio_write_disk_header+0xaf>
jmp    11d4 <sio_write_disk_header+0xb4>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d4 <sio_write_disk_header+0xb4>
mov    -0xc(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11d4 <sio_write_disk_header+0xb4>
jmp    11d4 <sio_write_disk_header+0xb4>
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0xc(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1040 <fputc@plt>
cmpl   $0x1,-0x10(%rbp)
jne    122c <sio_write_disk_header+0x10c>
mov    -0x8(%rbp),%rsi
mov    $0x80,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc@plt>
jmp    1245 <sio_write_disk_header+0x125>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rsi
mov    $0x1,%edi
call   1040 <fputc@plt>
mov    -0xc(%rbp),%edi
sar    $0x10,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1040 <fputc@plt>
mov    -0xc(%rbp),%edi
sar    $0x18,%edi
and    $0xff,%edi
mov    -0x8(%rbp),%rsi
call   1040 <fputc@plt>
movl   $0x8,-0x18(%rbp)
cmpl   $0xf,-0x18(%rbp)
jge    1299 <sio_write_disk_header+0x179>
mov    -0x8(%rbp),%rsi
xor    %edi,%edi
call   1040 <fputc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1276 <sio_write_disk_header+0x156>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_write_disk_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %edx,%r15d
mov    %esi,%r13d
mov    %rdi,%rbx
call   1030 <rewind@plt>
mov    $0x96,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
lea    -0x3(%r15),%eax
cmp    $0x2,%eax
jae    1164 <sio_write_disk_header+0x44>
add    %r13d,%r13d
jmp    1171 <sio_write_disk_header+0x51>
cmp    $0x2,%r15d
jne    1171 <sio_write_disk_header+0x51>
add    %r13d,%r13d
add    $0xfffffffd,%r13d
lea    0x0(,%r13,8),%r12d
movzbl %r12b,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %r13d,%eax
shr    $0x5,%eax
movzbl %al,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %ebp,%ebp
xor    %edi,%edi
cmp    $0x1,%r15d
setne  %bpl
sete   %dil
shl    $0x7,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
shr    $0xd,%r13d
movzbl %r13b,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
shr    $0x18,%r12d
mov    %r12d,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sio_write_disk_header(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = call i32 @rewind(i32* %10)
%12 = load i32*, i32** %5
%13 = call i32 @fputc(i32 150, i32* %12)
%14 = load i32*, i32** %5
%15 = call i32 @fputc(i32 2, i32* %14)
%16 = load i32, i32* %7
switch i32 %16, label %30 [
i32 1, label %17
i32 2, label %18
i32 3, label %27
i32 4, label %27
]
17: ; preds = %4
br label %31
18: ; preds = %4
%19 = load i32, i32* %6
%20 = sub nsw i32 %19, 3
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = shl i32 %21, 1
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 3
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = or i32 %25, 1
store i32 %26, i32* %6
br label %31
27: ; preds = %4, %4
%28 = load i32, i32* %6
%29 = shl i32 %28, 1
store i32 %29, i32* %6
br label %31
30: ; preds = %4
br label %31
31: ; preds = %30, %27, %18, %17
%32 = load i32, i32* %6
%33 = shl i32 %32, 3
store i32 %33, i32* %6
%34 = load i32, i32* %6
%35 = and i32 %34, 255
%36 = load i32*, i32** %5
%37 = call i32 @fputc(i32 %35, i32* %36)
%38 = load i32, i32* %6
%39 = ashr i32 %38, 8
%40 = and i32 %39, 255
%41 = load i32*, i32** %5
%42 = call i32 @fputc(i32 %40, i32* %41)
%43 = load i32, i32* %7
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %50
45: ; preds = %31
%46 = load i32*, i32** %5
%47 = call i32 @fputc(i32 128, i32* %46)
%48 = load i32*, i32** %5
%49 = call i32 @fputc(i32 0, i32* %48)
br label %55
50: ; preds = %31
%51 = load i32*, i32** %5
%52 = call i32 @fputc(i32 0, i32* %51)
%53 = load i32*, i32** %5
%54 = call i32 @fputc(i32 1, i32* %53)
br label %55
55: ; preds = %50, %45
%56 = load i32, i32* %6
%57 = ashr i32 %56, 16
%58 = and i32 %57, 255
%59 = load i32*, i32** %5
%60 = call i32 @fputc(i32 %58, i32* %59)
%61 = load i32, i32* %6
%62 = ashr i32 %61, 24
%63 = and i32 %62, 255
%64 = load i32*, i32** %5
%65 = call i32 @fputc(i32 %63, i32* %64)
store i32 8, i32* %9
br label %66
66: ; preds = %72, %55
%67 = load i32, i32* %9
%68 = icmp slt i32 %67, 15
br i1 %68, label %69, label %75
69: ; preds = %66
%70 = load i32*, i32** %5
%71 = call i32 @fputc(i32 0, i32* %70)
br label %72
72: ; preds = %69
%73 = load i32, i32* %9
%74 = add nsw i32 %73, 1
store i32 %74, i32* %9
br label %66
75: ; preds = %66
%76 = load i32, i32* %8
%77 = load i32*, i32** %5
%78 = call i32 @fputc(i32 %76, i32* %77)
ret i32 0
}

LLVM IR (-O2):
define i32 @sio_write_disk_header(i32* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @rewind(i32* %0)
%6 = tail call i32 @fputc(i32 150, i32* %0)
%7 = tail call i32 @fputc(i32 2, i32* %0)
switch i32 %2, label %13 [
i32 4, label %11
i32 2, label %8
i32 3, label %11
]
8: ; preds = %4
%9 = shl i32 %1, 1
%10 = add i32 %9, -3
br label %13
11: ; preds = %4, %4
%12 = shl i32 %1, 1
br label %13
13: ; preds = %4, %11, %8
%14 = phi i32 [ %1, %4 ], [ %10, %8 ], [ %12, %11 ]
%15 = shl i32 %14, 3
%16 = and i32 %15, 248
%17 = tail call i32 @fputc(i32 %16, i32* %0)
%18 = lshr i32 %15, 8
%19 = and i32 %18, 255
%20 = tail call i32 @fputc(i32 %19, i32* %0)
%21 = icmp eq i32 %2, 1
%22 = select i1 %21, i32 128, i32 0
%23 = xor i1 %21, true
%24 = zext i1 %23 to i32
%25 = tail call i32 @fputc(i32 %22, i32* %0)
%26 = tail call i32 @fputc(i32 %24, i32* %0)
%27 = lshr i32 %15, 16
%28 = and i32 %27, 255
%29 = tail call i32 @fputc(i32 %28, i32* %0)
%30 = lshr i32 %15, 24
%31 = tail call i32 @fputc(i32 %30, i32* %0)
%32 = tail call i32 @fputc(i32 0, i32* %0)
%33 = tail call i32 @fputc(i32 0, i32* %0)
%34 = tail call i32 @fputc(i32 0, i32* %0)
%35 = tail call i32 @fputc(i32 0, i32* %0)
%36 = tail call i32 @fputc(i32 0, i32* %0)
%37 = tail call i32 @fputc(i32 0, i32* %0)
%38 = tail call i32 @fputc(i32 0, i32* %0)
%39 = tail call i32 @fputc(i32 %3, i32* %0)
ret i32 0
}