#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*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  register int i;
  int fd;
  char drive;
  static unsigned char sector[128];
  static char fn[] = "disks/drive?.cpm";
  static char usage[] = "usage: format a | b | c | d | i | j | p";
  if (argc != 2) {
    puts(usage);
    exit(1);
  }
  i = *argv[1];
  if (argc != 2 || (i != 'a' && i != 'b' && i != 'c' && i != 'd' && i != 'i' &&
                    i != 'j' && i != 'p')) {
    puts(usage);
    exit(1);
  }
  fn[11] = drive = (char)i;
  memset((char *)sector, 0xe5, 128);
  if ((fd = creat(fn, 0644)) == -1) {
    perror("disk file");
    exit(1);
  }
  if (drive <= 'd') {
    for (i = 0; i < 77 * 26; i++)
      write(fd, (char *)sector, 128);
  } else if (drive == 'i' || drive == 'j') {
    for (i = 0; i < 255 * 128; i++)
      write(fd, (char *)sector, 128);
  } else if (drive == 'p') {
    for (i = 0; i < 256 * 16384; i++)
      write(fd, (char *)sector, 128);
  }
  close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11a6 <main+0x36>
lea    0x2ee9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1204 <main+0x94>
cmpl   $0x61,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x62,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x63,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x64,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x69,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x6a,-0x14(%rbp)
je     121a <main+0xaa>
cmpl   $0x70,-0x14(%rbp)
je     121a <main+0xaa>
lea    0x2e75(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %al,-0x19(%rbp)
mov    %al,0x2e45(%rip)
lea    0x2e93(%rip),%rdi
mov    $0xe5,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    0x2e1d(%rip),%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    126f <main+0xff>
lea    0xda0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movsbl -0x19(%rbp),%eax
cmp    $0x64,%eax
jg     12b7 <main+0x147>
movl   $0x0,-0x14(%rbp)
cmpl   $0x7d2,-0x14(%rbp)
jge    12b2 <main+0x142>
mov    -0x18(%rbp),%edi
lea    0x2e26(%rip),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1283 <main+0x113>
jmp    135e <main+0x1ee>
movsbl -0x19(%rbp),%eax
cmp    $0x69,%eax
je     12d1 <main+0x161>
movsbl -0x19(%rbp),%eax
cmp    $0x6a,%eax
jne    130c <main+0x19c>
movl   $0x0,-0x14(%rbp)
cmpl   $0x7f80,-0x14(%rbp)
jge    1307 <main+0x197>
mov    -0x18(%rbp),%edi
lea    0x2dd1(%rip),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12d8 <main+0x168>
jmp    1359 <main+0x1e9>
movsbl -0x19(%rbp),%eax
cmp    $0x70,%eax
jne    1354 <main+0x1e4>
movl   $0x0,-0x14(%rbp)
cmpl   $0x400000,-0x14(%rbp)
jge    134f <main+0x1df>
mov    -0x18(%rbp),%edi
lea    0x2d89(%rip),%rsi
mov    $0x80,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1320 <main+0x1b0>
jmp    1354 <main+0x1e4>
jmp    1359 <main+0x1e9>
jmp    135e <main+0x1ee>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    1272 <main+0x102>
mov    0x8(%rsi),%rax
mov    (%rax),%r14b
lea    -0x61(%r14),%eax
cmp    $0xf,%al
ja     1272 <main+0x102>
movzbl %al,%eax
mov    $0x830f,%ecx
bt     %rax,%rcx
jae    1272 <main+0x102>
mov    %r14b,0x2ec2(%rip)
lea    0x2eb0(%rip),%rbx
lea    0x2f09(%rip),%rdi
mov    $0xe5,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1080 <creat@plt>
cmp    $0xffffffff,%eax
je     1288 <main+0x118>
mov    %eax,%ebx
cmp    $0x64,%r14b
ja     1206 <main+0x96>
mov    $0x7d2,%ebp
lea    0x2ed0(%rip),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
jne    11f0 <main+0x80>
jmp    1264 <main+0xf4>
lea    -0x69(%r14),%eax
cmp    $0x1,%al
ja     1236 <main+0xc6>
mov    $0x7f80,%ebp
lea    0x2ea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
jne    1220 <main+0xb0>
jmp    1264 <main+0xf4>
cmp    $0x70,%r14b
jne    1264 <main+0xf4>
mov    $0x400000,%ebp
lea    0x2e78(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebp
jne    1250 <main+0xe0>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0x2e07(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xd71(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@main.sector = internal global [128 x i8] zeroinitializer
@main.fn = internal global [17 x i8] c"disks/drive?.cpm\00"
@main.usage = internal global [40 x i8] c"usage: format a | b | c | d | i | j | p\00"
@.str = [10 x i8] c"disk file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @main.usage, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
store i32 %19, i32* %6
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 2
br i1 %21, label %43, label %22
22: ; preds = %14
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 97
br i1 %24, label %25, label %46
25: ; preds = %22
%26 = load i32, i32* %6
%27 = icmp ne i32 %26, 98
br i1 %27, label %28, label %46
28: ; preds = %25
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 99
br i1 %30, label %31, label %46
31: ; preds = %28
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 100
br i1 %33, label %34, label %46
34: ; preds = %31
%35 = load i32, i32* %6
%36 = icmp ne i32 %35, 105
br i1 %36, label %37, label %46
37: ; preds = %34
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 106
br i1 %39, label %40, label %46
40: ; preds = %37
%41 = load i32, i32* %6
%42 = icmp ne i32 %41, 112
br i1 %42, label %43, label %46
43: ; preds = %40, %14
%44 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @main.usage, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40, %37, %34, %31, %28, %25, %22
%47 = load i32, i32* %6
%48 = trunc i32 %47 to i8
store i8 %48, i8* %8
store i8 %48, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @main.fn, i64 0, i64 11)
%49 = call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 229, i32 128)
%50 = call i32 @creat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @main.fn, i64 0, i64 0), i32 420)
store i32 %50, i32* %7
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %46
%53 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %46
%56 = load i8, i8* %8
%57 = sext i8 %56 to i32
%58 = icmp sle i32 %57, 100
br i1 %58, label %59, label %70
59: ; preds = %55
store i32 0, i32* %6
br label %60
60: ; preds = %66, %59
%61 = load i32, i32* %6
%62 = icmp slt i32 %61, 2002
br i1 %62, label %63, label %69
63: ; preds = %60
%64 = load i32, i32* %7
%65 = call i32 @write(i32 %64, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
br label %66
66: ; preds = %63
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %60
69: ; preds = %60
br label %106
70: ; preds = %55
%71 = load i8, i8* %8
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 105
br i1 %73, label %78, label %74
74: ; preds = %70
%75 = load i8, i8* %8
%76 = sext i8 %75 to i32
%77 = icmp eq i32 %76, 106
br i1 %77, label %78, label %89
78: ; preds = %74, %70
store i32 0, i32* %6
br label %79
79: ; preds = %85, %78
%80 = load i32, i32* %6
%81 = icmp slt i32 %80, 32640
br i1 %81, label %82, label %88
82: ; preds = %79
%83 = load i32, i32* %7
%84 = call i32 @write(i32 %83, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
br label %85
85: ; preds = %82
%86 = load i32, i32* %6
%87 = add nsw i32 %86, 1
store i32 %87, i32* %6
br label %79
88: ; preds = %79
br label %105
89: ; preds = %74
%90 = load i8, i8* %8
%91 = sext i8 %90 to i32
%92 = icmp eq i32 %91, 112
br i1 %92, label %93, label %104
93: ; preds = %89
store i32 0, i32* %6
br label %94
94: ; preds = %100, %93
%95 = load i32, i32* %6
%96 = icmp slt i32 %95, 4194304
br i1 %96, label %97, label %103
97: ; preds = %94
%98 = load i32, i32* %7
%99 = call i32 @write(i32 %98, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
br label %100
100: ; preds = %97
%101 = load i32, i32* %6
%102 = add nsw i32 %101, 1
store i32 %102, i32* %6
br label %94
103: ; preds = %94
br label %104
104: ; preds = %103, %89
br label %105
105: ; preds = %104, %88
br label %106
106: ; preds = %105, %69
%107 = load i32, i32* %7
%108 = call i32 @close(i32 %107)
ret i32 0
}

LLVM IR (-O2):
@main.sector = internal global [128 x i8] zeroinitializer
@main.fn = internal global [17 x i8] c"disks/drive?.cpm\00"
@main.usage = internal global [40 x i8] c"usage: format a | b | c | d | i | j | p\00"
@.str = [10 x i8] c"disk file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @main.usage, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i8, i8* %9
switch i8 %10, label %11 [
i8 112, label %14
i8 106, label %14
i8 105, label %14
i8 100, label %14
i8 99, label %14
i8 98, label %14
i8 97, label %14
]
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @main.usage, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7, %7, %7, %7, %7, %7, %7
store i8 %10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @main.fn, i64 0, i64 11)
%15 = tail call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 229, i32 128)
%16 = tail call i32 @creat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @main.fn, i64 0, i64 0), i32 420)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %14
%22 = icmp ult i8 %10, 101
br i1 %22, label %23, label %28
23: ; preds = %21, %23
%24 = phi i32 [ %26, %23 ], [ 0, %21 ]
%25 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
%26 = add nuw nsw i32 %24, 1
%27 = icmp eq i32 %26, 2002
br i1 %27, label %43, label %23
28: ; preds = %21
%29 = add nsw i8 %10, -105
%30 = icmp ult i8 %29, 2
br i1 %30, label %31, label %36
31: ; preds = %28, %31
%32 = phi i32 [ %34, %31 ], [ 0, %28 ]
%33 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
%34 = add nuw nsw i32 %32, 1
%35 = icmp eq i32 %34, 32640
br i1 %35, label %43, label %31
36: ; preds = %28
%37 = icmp eq i8 %10, 112
br i1 %37, label %38, label %43
38: ; preds = %36, %38
%39 = phi i32 [ %41, %38 ], [ 0, %36 ]
%40 = tail call i32 @write(i32 %16, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @main.sector, i64 0, i64 0), i32 128)
%41 = add nuw nsw i32 %39, 1
%42 = icmp eq i32 %41, 4194304
br i1 %42, label %43, label %38
43: ; preds = %38, %31, %23, %36
%44 = tail call i32 @close(i32 %16)
ret i32 0
}