#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 atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fatalmsg(char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ usage(char *);
void parse_mkfs(int argc, char **argv, int *magic_p, int *nblks_p,
                int *inodes_p) {
  int c;
  int namelen = 30;
  int version = 2;
  *nblks_p = -1;
  *inodes_p = 0;
  while (1) {
    c = getopt(argc, argv, "12vi:n:s:");
    if (c == -1)
      break;
    switch (c) {
    case '1':
      version = 1;
      break;
    case '2':
    case 'v':
      version = 2;
      break;
    case 'n':
      namelen = atoi(optarg);
      if (namelen != 30 || namelen != 14)
        fatalmsg("invalid name len (%d) must be 30 or 14", namelen);
    case 'i':
      *inodes_p = atoi(optarg);
      break;
    case 's':
      *nblks_p = atoi(optarg);
      break;
    default:
      usage(argv[0]);
    }
  }
  if (*nblks_p == -1)
    fatalmsg("no filesystem size specified");
  if (version == 2)
    *magic_p = namelen == 30 ? 0x2478 : 0x2468;
  else
    *magic_p = namelen == 30 ? 0x138F : 0x137F;
}


x86 assembly (clang, -O0):
<parse_mkfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x1e,-0x30(%rbp)
movl   $0x2,-0x34(%rbp)
mov    -0x20(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe75(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    11a2 <parse_mkfs+0x62>
jmp    12a5 <parse_mkfs+0x165>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x31,%eax
je     120b <parse_mkfs+0xcb>
jmp    11b6 <parse_mkfs+0x76>
mov    -0x38(%rbp),%eax
sub    $0x32,%eax
je     1217 <parse_mkfs+0xd7>
jmp    11c7 <parse_mkfs+0x87>
mov    -0x38(%rbp),%eax
sub    $0x69,%eax
je     125e <parse_mkfs+0x11e>
jmp    11d8 <parse_mkfs+0x98>
mov    -0x38(%rbp),%eax
sub    $0x6e,%eax
je     1223 <parse_mkfs+0xe3>
jmp    11e9 <parse_mkfs+0xa9>
mov    -0x38(%rbp),%eax
sub    $0x73,%eax
je     1279 <parse_mkfs+0x139>
jmp    11fa <parse_mkfs+0xba>
mov    -0x38(%rbp),%eax
sub    $0x76,%eax
je     1217 <parse_mkfs+0xd7>
jmp    1294 <parse_mkfs+0x154>
movl   $0x1,-0x34(%rbp)
jmp    12a0 <parse_mkfs+0x160>
movl   $0x2,-0x34(%rbp)
jmp    12a0 <parse_mkfs+0x160>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x1e,-0x30(%rbp)
jne    1248 <parse_mkfs+0x108>
cmpl   $0xe,-0x30(%rbp)
je     1259 <parse_mkfs+0x119>
mov    -0x30(%rbp),%esi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <fatalmsg@plt>
jmp    125e <parse_mkfs+0x11e>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a0 <parse_mkfs+0x160>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a0 <parse_mkfs+0x160>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <usage@plt>
jmp    117d <parse_mkfs+0x3d>
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    12c0 <parse_mkfs+0x180>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1040 <fatalmsg@plt>
cmpl   $0x2,-0x34(%rbp)
jne    12e8 <parse_mkfs+0x1a8>
mov    -0x30(%rbp),%edx
mov    $0x2468,%ecx
mov    $0x2478,%eax
cmp    $0x1e,%edx
cmove  %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    1301 <parse_mkfs+0x1c1>
mov    -0x30(%rbp),%edx
mov    $0x137f,%ecx
mov    $0x138f,%eax
cmp    $0x1e,%edx
cmove  %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mkfs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%r13
mov    %rdx,0x8(%rsp)
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0xffffffff,(%rcx)
movl   $0x2,(%rsp)
movl   $0x1e,0x4(%rsp)
lea    0xebc(%rip),%r14
lea    0xe7d(%rip),%r12
mov    0x2e6e(%rip),%r15
xor    %eax,%eax
jmp    11b4 <parse_mkfs+0x74>
xchg   %ax,%ax
mov    (%r15),%edi
call   1060 <atoi@plt>
lea    0xea3(%rip),%rdi
mov    %eax,0x4(%rsp)
mov    %eax,%esi
xor    %eax,%eax
call   1040 <fatalmsg@plt>
mov    (%r15),%edi
call   1060 <atoi@plt>
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
jmp    11c9 <parse_mkfs+0x89>
nopl   (%rax)
mov    0x0(%rbp),%rdi
call   1030 <usage@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
cmp    $0x68,%eax
jle    1200 <parse_mkfs+0xc0>
add    $0xffffff97,%eax
cmp    $0xd,%eax
ja     11c0 <parse_mkfs+0x80>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
mov    (%r15),%edi
call   1060 <atoi@plt>
mov    %eax,0x0(%r13)
jmp    11c9 <parse_mkfs+0x89>
nopw   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1221 <parse_mkfs+0xe1>
cmp    $0x31,%eax
je     1218 <parse_mkfs+0xd8>
cmp    $0x32,%eax
jne    11c0 <parse_mkfs+0x80>
movl   $0x2,(%rsp)
jmp    11c9 <parse_mkfs+0x89>
movl   $0x1,(%rsp)
jmp    11c9 <parse_mkfs+0x89>
cmpl   $0xffffffff,0x0(%r13)
jne    1236 <parse_mkfs+0xf6>
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1040 <fatalmsg@plt>
xor    %eax,%eax
cmpl   $0x1e,0x4(%rsp)
sete   %al
shl    $0x4,%eax
lea    0x137f(%rax),%ecx
or     $0x2468,%eax
cmpl   $0x2,(%rsp)
cmovne %ecx,%eax
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"12vi:n:s:\00"
@optarg = global i32 0
@.str.1 = [39 x i8] c"invalid name len (%d) must be 30 or 14\00"
@.str.2 = [29 x i8] c"no filesystem size specified\00"
define void @parse_mkfs(i32 %0, i8** %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
store i32 30, i32* %12
store i32 2, i32* %13
%14 = load i32*, i32** %9
store i32 -1, i32* %14
%15 = load i32*, i32** %10
store i32 0, i32* %15
br label %16
16: ; preds = %5, %52
%17 = load i32, i32* %6
%18 = load i8**, i8*** %7
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i32 %19, i32* %11
%20 = load i32, i32* %11
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
br label %53
23: ; preds = %16
%24 = load i32, i32* %11
switch i32 %24, label %47 [
i32 49, label %25
i32 50, label %26
i32 118, label %26
i32 110, label %27
i32 105, label %39
i32 115, label %43
]
25: ; preds = %23
store i32 1, i32* %13
br label %52
26: ; preds = %23, %23
store i32 2, i32* %13
br label %52
27: ; preds = %23
%28 = load i32, i32* @optarg
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = icmp ne i32 %30, 30
br i1 %31, label %35, label %32
32: ; preds = %27
%33 = load i32, i32* %12
%34 = icmp ne i32 %33, 14
br i1 %34, label %35, label %38
35: ; preds = %32, %27
%36 = load i32, i32* %12
%37 = call i32 (i8*, ...) @fatalmsg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %35, %32
br label %39
39: ; preds = %23, %38
%40 = load i32, i32* @optarg
%41 = call i32 @atoi(i32 %40)
%42 = load i32*, i32** %10
store i32 %41, i32* %42
br label %52
43: ; preds = %23
%44 = load i32, i32* @optarg
%45 = call i32 @atoi(i32 %44)
%46 = load i32*, i32** %9
store i32 %45, i32* %46
br label %52
47: ; preds = %23
%48 = load i8**, i8*** %7
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 @usage(i8* %50)
br label %52
52: ; preds = %47, %43, %39, %26, %25
br label %16
53: ; preds = %22
%54 = load i32*, i32** %9
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @fatalmsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %59
59: ; preds = %57, %53
%60 = load i32, i32* %13
%61 = icmp eq i32 %60, 2
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i32, i32* %12
%64 = icmp eq i32 %63, 30
%65 = zext i1 %64 to i64
%66 = select i1 %64, i32 9336, i32 9320
%67 = load i32*, i32** %8
store i32 %66, i32* %67
br label %74
68: ; preds = %59
%69 = load i32, i32* %12
%70 = icmp eq i32 %69, 30
%71 = zext i1 %70 to i64
%72 = select i1 %70, i32 5007, i32 4991
%73 = load i32*, i32** %8
store i32 %72, i32* %73
br label %74
74: ; preds = %68, %62
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"12vi:n:s:\00"
@optarg = global i32 0
@.str.1 = [39 x i8] c"invalid name len (%d) must be 30 or 14\00"
@.str.2 = [29 x i8] c"no filesystem size specified\00"
define void @parse_mkfs(i32 %0, i8** %1, i32* nocapture writeonly %2, i32* nocapture %3, i32* nocapture writeonly %4) {
store i32 -1, i32* %3
br label %6
6: ; preds = %21, %5
%7 = phi i32 [ 0, %5 ], [ %24, %21 ]
%8 = phi i32 [ 30, %5 ], [ %22, %21 ]
%9 = phi i32 [ 2, %5 ], [ %11, %21 ]
store i32 %7, i32* %4
br label %10
10: ; preds = %15, %6
%11 = phi i32 [ %9, %6 ], [ %16, %15 ]
br label %12
12: ; preds = %31, %10
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %28 [
i32 -1, label %32
i32 49, label %15
i32 50, label %14
i32 118, label %14
i32 110, label %17
i32 105, label %21
i32 115, label %25
]
14: ; preds = %12, %12
br label %15
15: ; preds = %12, %14
%16 = phi i32 [ 2, %14 ], [ 1, %12 ]
br label %10
17: ; preds = %12
%18 = load i32, i32* @optarg
%19 = tail call i32 @atoi(i32 %18)
%20 = tail call i32 (i8*, ...) @fatalmsg(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %12, %17
%22 = phi i32 [ %19, %17 ], [ %8, %12 ]
%23 = load i32, i32* @optarg
%24 = tail call i32 @atoi(i32 %23)
br label %6
25: ; preds = %12
%26 = load i32, i32* @optarg
%27 = tail call i32 @atoi(i32 %26)
store i32 %27, i32* %3
br label %31
28: ; preds = %12
%29 = load i8*, i8** %1
%30 = tail call i32 @usage(i8* %29)
br label %31
31: ; preds = %28, %25
br label %12
32: ; preds = %12
%33 = load i32, i32* %3
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 (i8*, ...) @fatalmsg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %32
%38 = icmp eq i32 %11, 2
%39 = icmp eq i32 %8, 30
%40 = select i1 %39, i32 5007, i32 4991
%41 = select i1 %39, i32 9336, i32 9320
%42 = select i1 %38, i32 %41, i32 %40
store i32 %42, i32* %2
ret void
}