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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int access(char *, int /*<<< orphan*/);
int atoi(char *);
scalar_t__ chdir(char *);
int /*<<< orphan*/ create_file(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *malloc(int);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int main(int argc, char *argv[]) {
  if (argc < 3) {
    perror("you haven't input the filename,please try again!\n");
    exit(EXIT_FAILURE);
  }
  int i, n = atoi(argv[1]), count = 1, k = atoi(argv[2]);
  while (n >= 10) {
    count++;
    n = n / 10;
  }
  char *str1 = malloc(sizeof(char) * (count) + 3);
  char *str2 = malloc(sizeof(char) * (count) + 1);
  if (access("data", 0) == -1) {
    if (mkdir("data", 0777)) {
      printf("Creat subdirectory failed!\n");
    }
  }
  if (chdir("data") == 0)
    printf("Switch to subdirectory\n");
  for (i = 0; i <= n; i++) {
    sprintf(str1, "f0");
    sprintf(str2, "%d", i);
    strcat(str1, str2);
    create_file(str1, k);
  }
  exit(EXIT_SUCCESS);
}


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)
jge    11ea <main+0x3a>
lea    0xe29(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xa,-0x18(%rbp)
jl     1237 <main+0x87>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
jmp    1211 <main+0x61>
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xdc6(%rip),%rdi
xor    %esi,%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    12a8 <main+0xf8>
lea    0xdaf(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
je     12a3 <main+0xf3>
lea    0xd99(%rip),%rdi
call   1050 <printf@plt>
jmp    12a8 <main+0xf8>
lea    0xd83(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jne    12ca <main+0x11a>
lea    0xd8e(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     132b <main+0x17b>
mov    -0x28(%rbp),%rdi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   10c0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1090 <create_file@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12d1 <main+0x121>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     11da <main+0x2a>
lea    0xe39(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    $0x1,%ebp
cmp    $0xa,%r15d
jl     1229 <main+0x79>
mov    $0x1,%ebp
mov    $0xcccccccd,%eax
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r15d,%ebx
imul   %rax,%rbx
shr    $0x23,%rbx
cmp    $0x63,%r15d
mov    %ebx,%r15d
ja     1210 <main+0x60>
jmp    122c <main+0x7c>
mov    %r15d,%ebx
lea    0x3(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,%r13
add    $0x1,%ebp
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
lea    0xde7(%rip),%rdi
xor    %esi,%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
jne    1279 <main+0xc9>
lea    0xdd4(%rip),%rdi
mov    $0x1ff,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
je     1279 <main+0xc9>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb2(%rip),%rdi
call   1050 <chdir@plt>
test   %rax,%rax
jne    1296 <main+0xe6>
lea    0xdac(%rip),%rdi
call   1040 <puts@plt>
test   %ebx,%ebx
js     12e8 <main+0x138>
add    $0x1,%ebx
lea    0xd96(%rip),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
movb   $0x0,0x2(%r13)
movw   $0x3066,0x0(%r13)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10c0 <sprintf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
mov    %r13,%rdi
mov    %r14d,%esi
call   1090 <create_file@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    12b0 <main+0x100>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [50 x i8] c"you haven't input the filename,please try again!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"data\00"
@.str.2 = [28 x i8] c"Creat subdirectory failed!\0A\00"
@.str.3 = [24 x i8] c"Switch to subdirectory\0A\00"
@.str.4 = [3 x i8] c"f0\00"
@.str.5 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 3
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %7
store i32 1, i32* %8
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %9
br label %27
27: ; preds = %30, %18
%28 = load i32, i32* %7
%29 = icmp sge i32 %28, 10
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
%33 = load i32, i32* %7
%34 = sdiv i32 %33, 10
store i32 %34, i32* %7
br label %27
35: ; preds = %27
%36 = load i32, i32* %8
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = add i64 %38, 3
%40 = trunc i64 %39 to i32
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %10
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = mul i64 1, %43
%45 = add i64 %44, 1
%46 = trunc i64 %45 to i32
%47 = call i8* @malloc(i32 %46)
store i8* %47, i8** %11
%48 = call i32 @access(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %56
50: ; preds = %35
%51 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 511)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
br label %56
56: ; preds = %55, %35
%57 = call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %59, %56
store i32 0, i32* %6
br label %62
62: ; preds = %78, %61
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = icmp sle i32 %63, %64
br i1 %65, label %66, label %81
66: ; preds = %62
%67 = load i8*, i8** %10
%68 = call i32 (i8*, i8*, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%69 = load i8*, i8** %11
%70 = load i32, i32* %6
%71 = call i32 (i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %70)
%72 = load i8*, i8** %10
%73 = load i8*, i8** %11
%74 = call i32 @strcat(i8* %72, i8* %73)
%75 = load i8*, i8** %10
%76 = load i32, i32* %9
%77 = call i32 @create_file(i8* %75, i32 %76)
br label %78
78: ; preds = %66
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %62
81: ; preds = %62
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
unreachable
}

LLVM IR (-O2):
@.str = [50 x i8] c"you haven't input the filename,please try again!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"data\00"
@.str.4 = [3 x i8] c"f0\00"
@.str.5 = [3 x i8] c"%d\00"
@EXIT_SUCCESS = global i32 0
@str = [23 x i8] c"Switch to subdirectory\00"
@str.6 = [27 x i8] c"Creat subdirectory failed!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %11, 9
br i1 %15, label %16, label %22
16: ; preds = %8, %16
%17 = phi i32 [ %20, %16 ], [ %11, %8 ]
%18 = phi i32 [ %19, %16 ], [ 1, %8 ]
%19 = add nuw nsw i32 %18, 1
%20 = udiv i32 %17, 10
%21 = icmp ugt i32 %17, 99
br i1 %21, label %16, label %22
22: ; preds = %16, %8
%23 = phi i32 [ 1, %8 ], [ %19, %16 ]
%24 = phi i32 [ %11, %8 ], [ %20, %16 ]
%25 = add nuw i32 %23, 3
%26 = tail call i8* @malloc(i32 %25)
%27 = add nuw i32 %23, 1
%28 = tail call i8* @malloc(i32 %27)
%29 = tail call i32 @access(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %36
31: ; preds = %22
%32 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 511)
%33 = icmp eq i64 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %31
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.6, i64 0, i64 0))
br label %36
36: ; preds = %31, %34, %22
%37 = tail call i64 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = icmp slt i32 %24, 0
br i1 %42, label %50, label %43
43: ; preds = %41, %43
%44 = phi i32 [ %48, %43 ], [ 0, %41 ]
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(3) %26, i8* align 1 dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3, i1 false)
%45 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %28, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %44)
%46 = tail call i32 @strcat(i8* %26, i8* %28)
%47 = tail call i32 @create_file(i8* %26, i32 %14)
%48 = add nuw i32 %44, 1
%49 = icmp eq i32 %44, %24
br i1 %49, label %50, label %43
50: ; preds = %43, %41
%51 = load i32, i32* @EXIT_SUCCESS
%52 = tail call i32 @exit(i32 %51)
unreachable
}