#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*/ check_dev(char const *, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ mklab5fs(char const *, int, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  const char *dev_path = NULL;
  int num_blocks = 0;
  int free_blocks = 0;
  const char *progname = argv[0];
  if (argc < 2) {
    printf("Usage: lab5mkfs <image file>\n");
    exit(1);
  }
  dev_path = argv[1];
  if (!check_dev(dev_path, &num_blocks))
    exit(1);
  free_blocks = num_blocks - (6 + 1);
  if (!mklab5fs(dev_path, num_blocks, free_blocks))
    exit(1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1197 <main+0x57>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <check_dev@plt>
cmp    $0x0,%eax
jne    11c3 <main+0x83>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
sub    $0x7,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1050 <mklab5fs@plt>
cmp    $0x0,%eax
jne    11ee <main+0xae>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
cmp    $0x1,%edi
jle    1182 <main+0x42>
mov    0x8(%rsi),%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <check_dev@plt>
test   %eax,%eax
je     118e <main+0x4e>
mov    0xc(%rsp),%esi
lea    -0x7(%rsi),%edx
mov    %rbx,%rdi
call   1050 <mklab5fs@plt>
test   %eax,%eax
je     118e <main+0x4e>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [30 x i8] c"Usage: lab5mkfs <image file>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
store i8* %12, i8** %9
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i32 @check_dev(i8* %22, i32* %7)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i32, i32* %7
%29 = sub nsw i32 %28, 7
store i32 %29, i32* %8
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = load i32, i32* %8
%33 = call i32 @mklab5fs(i8* %30, i32 %31, i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %27
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %27
ret i32 0
}

LLVM IR (-O2):
@str = [29 x i8] c"Usage: lab5mkfs <image file>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @check_dev(i8* %11, i32* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -7
%19 = call i32 @mklab5fs(i8* %11, i32 %17, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
ret i32 0
}