#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 u_int32_t;

/* Variables and functions */
int /*<<< orphan*/ check();
int /*<<< orphan*/ closedisk();
int diskblocks();
int diskblocksize();
int /*<<< orphan*/ errx(int, char *, ...);
int /*<<< orphan*/ opendisk(char *);
char *strchr(char *, char);
int strlen(char *);
int /*<<< orphan*/ writebitmap(int);
int /*<<< orphan*/ writerootdir();
int /*<<< orphan*/ writesuper(char *, int);
int main(int argc, char **argv) {
  u_int32_t size, blocksize;
  char *volname, *s;
  if (argc != 3) {
    errx(1, "Usage: mksfs device/diskfile volume-name");
  }
  check();
  volname = argv[2];
  s = strchr(volname, ':');
  if (s != NULL) {
    if (strlen(s) != 1) {
      errx(1, "Illegal volume name %s", volname);
    }
    *s = 0;
  }
  s = strchr(volname, '/');
  if (s != NULL) {
    errx(1, "Illegal volume name %s", volname);
  }
  opendisk(argv[1]);
  blocksize = diskblocksize();
  if (blocksize != 512) {
    errx(1, "Device has wrong blocksize %u (should be %u)\n", blocksize, 512);
  }
  size = diskblocks();
  writesuper(volname, size);
  writerootdir();
  writebitmap(size);
  closedisk();
  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)
cmpl   $0x3,-0x8(%rbp)
je     11e3 <main+0x33>
mov    $0x1,%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    $0x0,%al
call   10a0 <check@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1243 <main+0x93>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
je     123c <main+0x8c>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1277 <main+0xc7>
mov    -0x20(%rbp),%rdx
mov    $0x1,%edi
lea    0xdb9(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <opendisk@plt>
mov    $0x0,%al
call   1070 <diskblocksize@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x200,-0x18(%rbp)
je     12b6 <main+0x106>
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
lea    0xd96(%rip),%rsi
mov    $0x200,%ecx
mov    $0x0,%al
call   1040 <errx@plt>
mov    $0x0,%al
call   1080 <diskblocks@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <writesuper@plt>
mov    $0x0,%al
call   10c0 <writerootdir@plt>
mov    -0x14(%rbp),%edi
call   10d0 <writebitmap@plt>
mov    $0x0,%al
call   10b0 <closedisk@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x3,%edi
je     11d0 <main+0x20>
lea    0xe3c(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <errx@plt>
xor    %eax,%eax
call   10a0 <check@plt>
mov    0x10(%r14),%r15
mov    %r15,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     1216 <main+0x66>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
je     1213 <main+0x63>
lea    0xe25(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <errx@plt>
movb   $0x0,(%rbx)
mov    %r15,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123e <main+0x8e>
lea    0xdfa(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <errx@plt>
mov    0x8(%r14),%rdi
call   1090 <opendisk@plt>
xor    %eax,%eax
call   1070 <diskblocksize@plt>
cmp    $0x200,%eax
je     126f <main+0xbf>
lea    0xde4(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
mov    $0x200,%ecx
xor    %eax,%eax
call   1040 <errx@plt>
xor    %eax,%eax
call   1080 <diskblocks@plt>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
call   1060 <writesuper@plt>
xor    %eax,%eax
call   10c0 <writerootdir@plt>
mov    %ebx,%edi
call   10d0 <writebitmap@plt>
xor    %eax,%eax
call   10b0 <closedisk@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Usage: mksfs device/diskfile volume-name\00"
@.str.1 = [23 x i8] c"Illegal volume name %s\00"
@.str.2 = [46 x i8] c"Device has wrong blocksize %u (should be %u)\0A\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*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 (...) @check()
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = call i8* @strchr(i8* %19, i8 signext 58)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %32
23: ; preds = %14
%24 = load i8*, i8** %9
%25 = call i32 @strlen(i8* %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %8
%29 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %23
%31 = load i8*, i8** %9
store i8 0, i8* %31
br label %32
32: ; preds = %30, %14
%33 = load i8*, i8** %8
%34 = call i8* @strchr(i8* %33, i8 signext 47)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i8*, i8** %8
%39 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %32
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @opendisk(i8* %43)
%45 = call i32 (...) @diskblocksize()
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 512
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = load i32, i32* %7
%50 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 512)
br label %51
51: ; preds = %48, %40
%52 = call i32 (...) @diskblocks()
store i32 %52, i32* %6
%53 = load i8*, i8** %8
%54 = load i32, i32* %6
%55 = call i32 @writesuper(i8* %53, i32 %54)
%56 = call i32 (...) @writerootdir()
%57 = load i32, i32* %6
%58 = call i32 @writebitmap(i32 %57)
%59 = call i32 (...) @closedisk()
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Usage: mksfs device/diskfile volume-name\00"
@.str.1 = [23 x i8] c"Illegal volume name %s\00"
@.str.2 = [46 x i8] c"Device has wrong blocksize %u (should be %u)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = tail call i32 (...) @check()
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 58)
%11 = icmp eq i8* %10, null
br i1 %11, label %18, label %12
12: ; preds = %6
%13 = tail call i32 @strlen(i8* %10)
%14 = icmp eq i32 %13, 1
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %17
17: ; preds = %15, %12
store i8 0, i8* %10
br label %18
18: ; preds = %17, %6
%19 = tail call i8* @strchr(i8* dereferenceable(1) %9, i8 signext 47)
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %9)
br label %23
23: ; preds = %21, %18
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call i32 @opendisk(i8* %25)
%27 = tail call i32 (...) @diskblocksize()
%28 = icmp eq i32 %27, 512
br i1 %28, label %31, label %29
29: ; preds = %23
%30 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 512)
br label %31
31: ; preds = %29, %23
%32 = tail call i32 (...) @diskblocks()
%33 = tail call i32 @writesuper(i8* %9, i32 %32)
%34 = tail call i32 (...) @writerootdir()
%35 = tail call i32 @writebitmap(i32 %32)
%36 = tail call i32 (...) @closedisk()
ret i32 0
}