#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*/ time_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ scanf(char *, int *, int *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ system(char *);
scalar_t__ time(int /*<<< orphan*/ *);
int main() {
  int n, k;
  int i;
  char str[20];
  time_t t;
  printf("Input n & k for number of files and range of random numbers.\n");
  scanf("%d %d", &n, &k);
  system("mkdir data");
  system("chmod 777 data");
  srand((unsigned)time(&t));
  for (i = 0; i < n; i++) {
    FILE *fp;
    sprintf(str, "data/f%d", i);
    fp = fopen(str, "w");
    fprintf(fp, "%d", rand() % k + 1);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7c(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1090 <scanf@plt>
lea    0xe6e(%rip),%rdi
call   1040 <system@plt>
lea    0xe6d(%rip),%rdi
call   1040 <system@plt>
lea    -0x34(%rbp),%rdi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    126e <main+0xce>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xe46(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x30(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10c0 <rand@plt>
mov    -0x48(%rbp),%rdi
cltd
idivl  -0xc(%rbp)
add    $0x1,%edx
lea    0xdef(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11fe <main+0x5e>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3f(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1090 <scanf@plt>
lea    0xe2f(%rip),%rdi
call   1050 <system@plt>
lea    0xe2e(%rip),%rdi
call   1050 <system@plt>
lea    0xc(%rsp),%rdi
call   1080 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
cmpl   $0x0,0x4(%rsp)
jle    1266 <main+0xc6>
lea    0xe19(%rip),%r14
lea    0x10(%rsp),%r13
lea    0xe16(%rip),%r15
lea    0xde9(%rip),%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10c0 <rand@plt>
cltd
idivl  0x8(%rsp)
add    $0x1,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x1,%ebp
cmp    0x4(%rsp),%ebp
jl     1220 <main+0x80>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"Input n & k for number of files and range of random numbers.\0A\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [11 x i8] c"mkdir data\00"
@.str.3 = [15 x i8] c"chmod 777 data\00"
@.str.4 = [9 x i8] c"data/f%d\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [20 x i8]
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%10 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%12 = call i64 @time(i32* %6)
%13 = trunc i64 %12 to i32
%14 = call i32 @srand(i32 %13)
store i32 0, i32* %4
br label %15
15: ; preds = %33, %0
%16 = load i32, i32* %4
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %4
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %24, i32** %7
%25 = load i32*, i32** %7
%26 = call i32 (...) @rand()
%27 = load i32, i32* %3
%28 = srem i32 %26, %27
%29 = add nsw i32 %28, 1
%30 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %19
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %15
36: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [11 x i8] c"mkdir data\00"
@.str.3 = [15 x i8] c"chmod 777 data\00"
@.str.4 = [9 x i8] c"data/f%d\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [3 x i8] c"%d\00"
@str = [61 x i8] c"Input n & k for number of files and range of random numbers.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca i32
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%11 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%13 = call i64 @time(i32* %4)
%14 = trunc i64 %13 to i32
%15 = call i32 @srand(i32 %14)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %0, %18
%19 = phi i32 [ %28, %18 ], [ 0, %0 ]
%20 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (...) @rand()
%23 = load i32, i32* %2
%24 = srem i32 %22, %23
%25 = add nsw i32 %24, 1
%26 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %25)
%27 = call i32 @fclose(i32* %21)
%28 = add nuw nsw i32 %19, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %28, %29
br i1 %30, label %18, label %31
31: ; preds = %18, %0
ret i32 0
}