#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ sio_write_disk_header(int /*<<< orphan*/ *, int, int,
                                         int /*<<< orphan*/);
int sio_create_disk(const char *filename, int num_sectors, int disk_type) {
  FILE *fp;
  int size;
  int i;
  switch (disk_type) {
  case 0x01:
    size = 128 * num_sectors;
    break;
  case 0x02:
    size = (256 * (num_sectors - 3)) + (128 * 3);
    break;
  default:
    size = 256 * num_sectors;
    break;
  }
  fp = fopen(filename, "wb");
  if (!fp)
    return -1;
  sio_write_disk_header(fp, num_sectors, disk_type, 0);
  for (i = 0; i < size; ++i)
    fputc(0, fp);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<sio_create_disk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x1,%eax
je     1177 <sio_create_disk+0x37>
jmp    1166 <sio_create_disk+0x26>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     1185 <sio_create_disk+0x45>
jmp    119b <sio_create_disk+0x5b>
mov    -0x14(%rbp),%eax
shl    $0x7,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <sio_create_disk+0x64>
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
shl    $0x8,%eax
add    $0x180,%eax
mov    %eax,-0x24(%rbp)
jmp    11a4 <sio_create_disk+0x64>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11cf <sio_create_disk+0x8f>
movl   $0xffffffff,-0x4(%rbp)
jmp    121c <sio_create_disk+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
xor    %ecx,%ecx
call   1030 <sio_write_disk_header@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    120c <sio_create_disk+0xcc>
mov    -0x20(%rbp),%rsi
xor    %edi,%edi
call   1050 <fputc@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e7 <sio_create_disk+0xa7>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sio_create_disk>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r15d
mov    %esi,%ebx
cmp    $0x2,%edx
je     1160 <sio_create_disk+0x20>
cmp    $0x1,%r12d
jne    116b <sio_create_disk+0x2b>
shl    $0x7,%ebx
jmp    116e <sio_create_disk+0x2e>
shl    $0x8,%ebx
add    $0xfffffe80,%ebx
jmp    116e <sio_create_disk+0x2e>
shl    $0x8,%ebx
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b9 <sio_create_disk+0x79>
mov    %rax,%rbp
xor    %r14d,%r14d
mov    %rax,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
call   1030 <sio_write_disk_header@plt>
test   %ebx,%ebx
jle    11af <sio_create_disk+0x6f>
nopl   0x0(%rax)
xor    %edi,%edi
mov    %rbp,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebx
jne    11a0 <sio_create_disk+0x60>
mov    %rbp,%rdi
call   1040 <fclose@plt>
jmp    11bf <sio_create_disk+0x7f>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define i32 @sio_create_disk(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%11 = load i32, i32* %7
switch i32 %11, label %20 [
i32 1, label %12
i32 2, label %15
]
12: ; preds = %3
%13 = load i32, i32* %6
%14 = mul nsw i32 128, %13
store i32 %14, i32* %9
br label %23
15: ; preds = %3
%16 = load i32, i32* %6
%17 = sub nsw i32 %16, 3
%18 = mul nsw i32 256, %17
%19 = add nsw i32 %18, 384
store i32 %19, i32* %9
br label %23
20: ; preds = %3
%21 = load i32, i32* %6
%22 = mul nsw i32 256, %21
store i32 %22, i32* %9
br label %23
23: ; preds = %20, %15, %12
%24 = load i8*, i8** %5
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %8
%26 = load i32*, i32** %8
%27 = icmp ne i32* %26, null
br i1 %27, label %29, label %28
28: ; preds = %23
store i32 -1, i32* %4
br label %47
29: ; preds = %23
%30 = load i32*, i32** %8
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 @sio_write_disk_header(i32* %30, i32 %31, i32 %32, i32 0)
store i32 0, i32* %10
br label %34
34: ; preds = %41, %29
%35 = load i32, i32* %10
%36 = load i32, i32* %9
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %44
38: ; preds = %34
%39 = load i32*, i32** %8
%40 = call i32 @fputc(i32 0, i32* %39)
br label %41
41: ; preds = %38
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %34
44: ; preds = %34
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
store i32 0, i32* %4
br label %47
47: ; preds = %44, %28
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @sio_create_disk(i8* nocapture %0, i32 %1, i32 %2) {
switch i32 %2, label %9 [
i32 1, label %4
i32 2, label %6
]
4: ; preds = %3
%5 = shl nsw i32 %1, 7
br label %11
6: ; preds = %3
%7 = shl i32 %1, 8
%8 = add i32 %7, -384
br label %11
9: ; preds = %3
%10 = shl nsw i32 %1, 8
br label %11
11: ; preds = %9, %6, %4
%12 = phi i32 [ %10, %9 ], [ %8, %6 ], [ %5, %4 ]
%13 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %25, label %15
15: ; preds = %11
%16 = tail call i32 @sio_write_disk_header(i32* %13, i32 %1, i32 %2, i32 0)
%17 = icmp sgt i32 %12, 0
br i1 %17, label %18, label %23
18: ; preds = %15, %18
%19 = phi i32 [ %21, %18 ], [ 0, %15 ]
%20 = tail call i32 @fputc(i32 0, i32* %13)
%21 = add nuw nsw i32 %19, 1
%22 = icmp eq i32 %21, %12
br i1 %22, label %23, label %18
23: ; preds = %18, %15
%24 = tail call i32 @fclose(i32* %13)
br label %25
25: ; preds = %11, %23
%26 = phi i32 [ 0, %23 ], [ -1, %11 ]
ret i32 %26
}