#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*/ EXIT_FAILURE;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, int, ...);
void prepare_dirs(char *path, int id, int fnum) {
  int i;
  int mkstat;
  int dname;
  char str[1024];
  sprintf(str, "%s/%04d", path, id);
  mkstat = mkdir(str, S_IRWXU | S_IRWXG | S_IRWXO);
  if (mkstat < 0) {
    perror(str);
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < fnum; i = i + 100) {
    dname = i / 100;
    sprintf(str, "%s/%04d/%04d", path, id, dname);
    mkstat = mkdir(str, S_IRWXU | S_IRWXG | S_IRWXO);
    if (mkstat < 0) {
      perror(str);
      exit(EXIT_FAILURE);
    }
  }
}


x86 assembly (clang, -O0):
<prepare_dirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
mov    0x2e50(%rip),%rax
or     (%rax),%esi
mov    0x2e5f(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11bf <prepare_dirs+0x7f>
lea    -0x420(%rbp),%rdi
call   1040 <perror@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1261 <prepare_dirs+0x121>
mov    -0x14(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2dd2(%rip),%rax
mov    (%rax),%esi
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    0x2dd0(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    124e <prepare_dirs+0x10e>
lea    -0x420(%rbp),%rdi
call   1040 <perror@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1253 <prepare_dirs+0x113>
mov    -0x14(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0x14(%rbp)
jmp    11c6 <prepare_dirs+0x86>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_dirs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r14d
mov    %esi,%r12d
mov    %rdi,%r13
lea    0xe9f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r13,%rdx
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    0x2e65(%rip),%rax
mov    0x2e56(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e63(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
test   %eax,%eax
js     120f <prepare_dirs+0xcf>
test   %r14d,%r14d
jle    11fd <prepare_dirs+0xbd>
mov    %rsp,%rbp
xor    %ebx,%ebx
xor    %r15d,%r15d
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xe4e(%rip),%rsi
mov    %r13,%rdx
mov    %r12d,%ecx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
mov    0x2e0d(%rip),%rax
or     (%rax),%esi
mov    %rbp,%rdi
call   1030 <mkdir@plt>
test   %eax,%eax
js     120f <prepare_dirs+0xcf>
add    $0x64,%r15d
add    $0x1,%ebx
cmp    %r14d,%r15d
jl     11b0 <prepare_dirs+0x70>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rdi
call   1040 <perror@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%s/%04d\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"%s/%04d/%04d\00"
define void @prepare_dirs(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* @S_IRWXU
%17 = load i32, i32* @S_IRWXG
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IRWXO
%20 = or i32 %18, %19
%21 = call i32 @mkdir(i8* %15, i32 %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%26 = call i32 @perror(i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %3
store i32 0, i32* %7
br label %30
30: ; preds = %57, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %60
34: ; preds = %30
%35 = load i32, i32* %7
%36 = sdiv i32 %35, 100
store i32 %36, i32* %9
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%38 = load i8*, i8** %4
%39 = load i32, i32* %5
%40 = load i32, i32* %9
%41 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %39, i32 %40)
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%43 = load i32, i32* @S_IRWXU
%44 = load i32, i32* @S_IRWXG
%45 = or i32 %43, %44
%46 = load i32, i32* @S_IRWXO
%47 = or i32 %45, %46
%48 = call i32 @mkdir(i8* %42, i32 %47)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %34
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%53 = call i32 @perror(i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %34
br label %57
57: ; preds = %56
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 100
store i32 %59, i32* %7
br label %30
60: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/%04d\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [13 x i8] c"%s/%04d/%04d\00"
define void @prepare_dirs(i8* %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%7 = load i32, i32* @S_IRWXU
%8 = load i32, i32* @S_IRWXG
%9 = or i32 %8, %7
%10 = load i32, i32* @S_IRWXO
%11 = or i32 %9, %10
%12 = call i32 @mkdir(i8* %5, i32 %11)
%13 = icmp slt i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %3
%15 = icmp sgt i32 %2, 0
br i1 %15, label %22, label %38
16: ; preds = %3
%17 = call i32 @perror(i8* %5)
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %22
%21 = icmp slt i32 %33, %2
br i1 %21, label %22, label %38
22: ; preds = %14, %20
%23 = phi i32 [ %33, %20 ], [ 0, %14 ]
%24 = udiv i32 %23, 100
%25 = call i32 (i8*, i8*, i8*, i32, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i32 %24)
%26 = load i32, i32* @S_IRWXU
%27 = load i32, i32* @S_IRWXG
%28 = or i32 %27, %26
%29 = load i32, i32* @S_IRWXO
%30 = or i32 %28, %29
%31 = call i32 @mkdir(i8* %5, i32 %30)
%32 = icmp slt i32 %31, 0
%33 = add nuw nsw i32 %23, 100
br i1 %32, label %34, label %20
34: ; preds = %22
%35 = call i32 @perror(i8* %5)
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @exit(i32 %36)
unreachable
38: ; preds = %20, %14
ret void
}