#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 /*<<< orphan*/ path;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
scalar_t__ close(int);
int creat(char *, int);
int /*<<< orphan*/ err_exit(char *, char *);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, int, int);
void fsobj_create(char **searchpath, int length, int files) {
  char path[PATH_MAX + 1];
  int i, j, fd;
  for (i = 0; i < length; i++) {
    if (mkdir(searchpath[i], 0777) < 0)
      err_exit("mkdir %s", searchpath[i]);
    for (j = 0; j < files; j++) {
      snprintf(path, sizeof(path), "%s/%d.%d", searchpath[i], i, j);
      if ((fd = creat(path, 0644)) < 0)
        err_exit("creat %s", path);
      if (close(fd) < 0)
        err_exit("close %s", path);
    }
  }
}


x86 assembly (clang, -O0):
<fsobj_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    128f <fsobj_create+0x13f>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    11e0 <fsobj_create+0x90>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe25(%rip),%rdi
call   1060 <err_exit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    127c <fsobj_create+0x12c>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xdf1(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x38(%rbp),%rdi
mov    $0x1a4,%esi
call   1070 <creat@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    1247 <fsobj_create+0xf7>
mov    -0x38(%rbp),%rsi
lea    0xdd0(%rip),%rdi
call   1060 <err_exit@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    1269 <fsobj_create+0x119>
mov    -0x38(%rbp),%rsi
lea    0xdb7(%rip),%rdi
call   1060 <err_exit@plt>
jmp    126e <fsobj_create+0x11e>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11e7 <fsobj_create+0x97>
jmp    1281 <fsobj_create+0x131>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    119c <fsobj_create+0x4c>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsobj_create>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,-0x2c(%rbp)
mov    %rdi,-0x38(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
mov    %rax,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
test   %esi,%esi
jle    125b <fsobj_create+0x10b>
mov    %esi,%eax
mov    %rax,-0x40(%rbp)
xor    %r13d,%r13d
jmp    11ae <fsobj_create+0x5e>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    -0x40(%rbp),%r13
je     125b <fsobj_create+0x10b>
mov    -0x38(%rbp),%rax
mov    (%rax,%r13,8),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
js     11d0 <fsobj_create+0x80>
cmpl   $0x0,-0x2c(%rbp)
jg     11ea <fsobj_create+0x9a>
jmp    11a0 <fsobj_create+0x50>
nopl   (%rax)
mov    -0x38(%rbp),%rax
mov    (%rax,%r13,8),%rsi
lea    0xe21(%rip),%rdi
call   1060 <err_exit@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11a0 <fsobj_create+0x50>
xor    %r15d,%r15d
jmp    11fa <fsobj_create+0xaa>
nop
add    $0x1,%r15d
cmp    %r15d,-0x2c(%rbp)
je     11a0 <fsobj_create+0x50>
mov    -0x38(%rbp),%rax
mov    (%rax,%r13,8),%rcx
mov    %rbx,%rdi
mov    %r12d,%esi
lea    0xdfa(%rip),%rdx
mov    %r13d,%r8d
mov    %r15d,%r9d
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    $0x1a4,%esi
call   1070 <creat@plt>
mov    %eax,%r14d
test   %eax,%eax
jns    123d <fsobj_create+0xed>
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
call   1060 <err_exit@plt>
mov    %r14d,%edi
call   1050 <close@plt>
test   %rax,%rax
jns    11f0 <fsobj_create+0xa0>
lea    0xdca(%rip),%rdi
mov    %rbx,%rsi
call   1060 <err_exit@plt>
jmp    11f0 <fsobj_create+0xa0>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [9 x i8] c"mkdir %s\00"
@.str.1 = [9 x i8] c"%s/%d.%d\00"
@.str.2 = [9 x i8] c"creat %s\00"
@.str.3 = [9 x i8] c"close %s\00"
define void @fsobj_create(i8** %0, i32 %1, i32 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* @PATH_MAX
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %7
%16 = alloca i8, i64 %14
store i64 %14, i64* %8
store i32 0, i32* %9
br label %17
17: ; preds = %66, %3
%18 = load i32, i32* %9
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %69
21: ; preds = %17
%22 = load i8**, i8*** %4
%23 = load i32, i32* %9
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @mkdir(i8* %26, i32 511)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = load i8**, i8*** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %29, %21
store i32 0, i32* %10
br label %37
37: ; preds = %62, %36
%38 = load i32, i32* %10
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %65
41: ; preds = %37
%42 = trunc i64 %14 to i32
%43 = load i8**, i8*** %4
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = call i32 @snprintf(i8* %16, i32 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %47, i32 %48, i32 %49)
%51 = call i32 @creat(i8* %16, i32 420)
store i32 %51, i32* %11
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %41
%54 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %55
55: ; preds = %53, %41
%56 = load i32, i32* %11
%57 = call i64 @close(i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %16)
br label %61
61: ; preds = %59, %55
br label %62
62: ; preds = %61
%63 = load i32, i32* %10
%64 = add nsw i32 %63, 1
store i32 %64, i32* %10
br label %37
65: ; preds = %37
br label %66
66: ; preds = %65
%67 = load i32, i32* %9
%68 = add nsw i32 %67, 1
store i32 %68, i32* %9
br label %17
69: ; preds = %17
%70 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [9 x i8] c"mkdir %s\00"
@.str.1 = [9 x i8] c"%s/%d.%d\00"
@.str.2 = [9 x i8] c"creat %s\00"
@.str.3 = [9 x i8] c"close %s\00"
define void @fsobj_create(i8** nocapture %0, i32 %1, i32 %2) {
%4 = load i32, i32* @PATH_MAX
%5 = add nsw i32 %4, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %43
9: ; preds = %3
%10 = icmp sgt i32 %2, 0
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %9, %40
%13 = phi i64 [ 0, %9 ], [ %41, %40 ]
%14 = getelementptr inbounds i8*, i8** %0, i64 %13
%15 = load i8*, i8** %14
%16 = call i64 @mkdir(i8* %15, i32 511)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %14
%20 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %12
br i1 %10, label %22, label %40
22: ; preds = %21
%23 = trunc i64 %13 to i32
br label %24
24: ; preds = %22, %37
%25 = phi i32 [ %38, %37 ], [ 0, %22 ]
%26 = load i8*, i8** %14
%27 = call i32 @snprintf(i8* %7, i32 %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %23, i32 %25)
%28 = call i32 @creat(i8* %7, i32 420)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %32
32: ; preds = %30, %24
%33 = call i64 @close(i32 %28)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @err_exit(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %7)
br label %37
37: ; preds = %32, %35
%38 = add nuw nsw i32 %25, 1
%39 = icmp eq i32 %38, %2
br i1 %39, label %40, label %24
40: ; preds = %37, %21
%41 = add nuw nsw i64 %13, 1
%42 = icmp eq i64 %41, %11
br i1 %42, label %43, label %12
43: ; preds = %40, %3
ret void
}