#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 */
struct minix_fs_dat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ close_fs(struct minix_fs_dat *);
struct minix_fs_dat *new_fs(char *, int, int, int);
int optind;
int /*<<< orphan*/ parse_mkfs(int, char **, int *, int *, int *);
int /*<<< orphan*/ printf(char *, int, char *);
void cmd_genfs(int argc, char **argv) {
  int req_inos;
  int req_blks;
  int magic;
  char *filename = argv[0];
  struct minix_fs_dat *fs;
  parse_mkfs(argc, argv, &magic, &req_blks, &req_inos);
  fs = new_fs(filename, magic, req_blks, req_inos);
  {
    int i;
    for (i = optind; i < argc; i++) {
      printf("%3d) %s\n", i, argv[i]);
    }
  }
  close_fs(fs);
}


x86 assembly (clang, -O0):
<cmd_genfs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x18(%rbp),%rcx
lea    -0x14(%rbp),%r8
call   1040 <parse_mkfs@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1060 <new_fs@plt>
mov    %rax,-0x30(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <cmd_genfs+0x89>
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1194 <cmd_genfs+0x54>
mov    -0x30(%rbp),%rdi
call   1050 <close_fs@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_genfs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %edi,%r12d
mov    (%rsi),%rbp
lea    0x4(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0xc(%rsp),%r8
call   1040 <parse_mkfs@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    %rbp,%rdi
call   1060 <new_fs@plt>
mov    %rax,%r14
mov    0x2e61(%rip),%rax
mov    (%rax),%ebp
cmp    %r12d,%ebp
jge    11b9 <cmd_genfs+0x79>
movslq %ebp,%rax
lea    (%r15,%rax,8),%rbx
lea    0xe64(%rip),%r15
nopl   0x0(%rax)
mov    (%rbx),%rdx
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%ebp
add    $0x8,%rbx
cmp    %ebp,%r12d
jne    11a0 <cmd_genfs+0x60>
mov    %r14,%rdi
call   1050 <close_fs@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.minix_fs_dat = type { i32 }
@optind = global i32 0
@.str = [9 x i8] c"%3d) %s\0A\00"
define void @cmd_genfs(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.minix_fs_dat*
%10 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
store i8* %13, i8** %8
%14 = load i32, i32* %3
%15 = load i8**, i8*** %4
%16 = call i32 @parse_mkfs(i32 %14, i8** %15, i32* %7, i32* %6, i32* %5)
%17 = load i8*, i8** %8
%18 = load i32, i32* %7
%19 = load i32, i32* %6
%20 = load i32, i32* %5
%21 = call %struct.minix_fs_dat* @new_fs(i8* %17, i32 %18, i32 %19, i32 %20)
store %struct.minix_fs_dat* %21, %struct.minix_fs_dat** %9
%22 = load i32, i32* @optind
store i32 %22, i32* %10
br label %23
23: ; preds = %35, %2
%24 = load i32, i32* %10
%25 = load i32, i32* %3
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i32, i32* %10
%29 = load i8**, i8*** %4
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %28, i8* %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 1
store i32 %37, i32* %10
br label %23
38: ; preds = %23
%39 = load %struct.minix_fs_dat*, %struct.minix_fs_dat** %9
%40 = call i32 @close_fs(%struct.minix_fs_dat* %39)
ret void
}

LLVM IR (-O2):
%struct.minix_fs_dat = type { i32 }
@optind = global i32 0
@.str = [9 x i8] c"%3d) %s\0A\00"
define void @cmd_genfs(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = load i8*, i8** %1
%10 = call i32 @parse_mkfs(i32 %0, i8** %1, i32* %5, i32* %4, i32* %3)
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = call %struct.minix_fs_dat* @new_fs(i8* %9, i32 %11, i32 %12, i32 %13)
%15 = load i32, i32* @optind
%16 = icmp slt i32 %15, %0
br i1 %16, label %17, label %28
17: ; preds = %2
%18 = sext i32 %15 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ %18, %17 ], [ %25, %19 ]
%21 = getelementptr inbounds i8*, i8** %1, i64 %20
%22 = load i8*, i8** %21
%23 = trunc i64 %20 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %23, i8* %22)
%25 = add nsw i64 %20, 1
%26 = trunc i64 %25 to i32
%27 = icmp eq i32 %26, %0
br i1 %27, label %28, label %19
28: ; preds = %19, %2
%29 = call i32 @close_fs(%struct.minix_fs_dat* %14)
ret void
}