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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  if (argc < 4) {
    fprintf(stderr,
            "Errore nei parametri!\nUtilizzo: %s <n_compiti> <n_risorse> "
            "<intervallo>\n",
            argv[0]);
    return -1;
  }
  int n_compiti = atoi(argv[1]);
  int n_risorse = atoi(argv[2]);
  int intervallo = atoi(argv[3]);
  FILE *fp;
  int i;
  srand(time(NULL));
  fp = fopen("compiti_rand.txt", "w");
  for (i = 0; i < n_compiti; i++) {
    fprintf(fp, "Job%d\t\t%d\n", i, rand() % intervallo);
  }
  fclose(fp);
  fp = fopen("risorse_rand.txt", "w");
  for (i = 0; i < n_risorse; i++)
    fprintf(fp, "Risorsa%d\n", i);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11bb <main+0x4b>
mov    0x2e49(%rip),%rax
movslq (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c9 <main+0x159>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe47(%rip),%rdi
lea    0xe51(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1263 <main+0xf3>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1090 <rand@plt>
mov    -0x38(%rbp),%rdi
cltd
idivl  -0x1c(%rbp)
mov    %edx,%ecx
mov    -0x30(%rbp),%edx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1219 <main+0xa9>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdf4(%rip),%rdi
lea    0xde0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12b9 <main+0x149>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    128a <main+0x11a>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     11a8 <main+0x38>
mov    0x2e56(%rip),%rax
movslq (%rax),%rdi
mov    (%rbx),%rdx
lea    0xe69(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1271 <main+0x101>
mov    0x8(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
mov    0x18(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r13d
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
lea    0xe68(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %r15d,%r15d
jle    1224 <main+0xb4>
lea    0xe60(%rip),%r12
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
cltd
idiv   %r13d
mov    %edx,%ecx
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%ebx
cmp    %ebx,%r15d
jne    1200 <main+0x90>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xe34(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %r14d,%r14d
jle    1267 <main+0xf7>
lea    0xe2a(%rip),%r15
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1250 <main+0xe0>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [73 x i8] c"Errore nei parametri!\0AUtilizzo: %s <n_compiti> <n_risorse> <intervallo>\0A\00"
@.str.1 = [17 x i8] c"compiti_rand.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [11 x i8] c"Job%d\09\09%d\0A\00"
@.str.4 = [17 x i8] c"risorse_rand.txt\00"
@.str.5 = [11 x i8] c"Risorsa%d\0A\00"
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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = sext i32 %14 to i64
%16 = inttoptr i64 %15 to i32*
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 -1, i32* %3
br label %69
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %7
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = call i32 @time(i32* null)
%35 = call i32 @srand(i32 %34)
%36 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %36, i32** %9
store i32 0, i32* %10
br label %37
37: ; preds = %48, %21
%38 = load i32, i32* %10
%39 = load i32, i32* %6
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i32*, i32** %9
%43 = load i32, i32* %10
%44 = call i32 (...) @rand()
%45 = load i32, i32* %8
%46 = srem i32 %44, %45
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %43, i32 %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %37
51: ; preds = %37
%52 = load i32*, i32** %9
%53 = call i32 @fclose(i32* %52)
%54 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %54, i32** %9
store i32 0, i32* %10
br label %55
55: ; preds = %63, %51
%56 = load i32, i32* %10
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %66
59: ; preds = %55
%60 = load i32*, i32** %9
%61 = load i32, i32* %10
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %61)
br label %63
63: ; preds = %59
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %55
66: ; preds = %55
%67 = load i32*, i32** %9
%68 = call i32 @fclose(i32* %67)
store i32 0, i32* %3
br label %69
69: ; preds = %66, %13
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [73 x i8] c"Errore nei parametri!\0AUtilizzo: %s <n_compiti> <n_risorse> <intervallo>\0A\00"
@.str.1 = [17 x i8] c"compiti_rand.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [11 x i8] c"Job%d\09\09%d\0A\00"
@.str.4 = [17 x i8] c"risorse_rand.txt\00"
@.str.5 = [11 x i8] c"Risorsa%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = sext i32 %5 to i64
%7 = inttoptr i64 %6 to i32*
%8 = load i8*, i8** %1
%9 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %42
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = tail call i32 @time(i32* null)
%21 = tail call i32 @srand(i32 %20)
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp sgt i32 %13, 0
br i1 %23, label %24, label %31
24: ; preds = %10, %24
%25 = phi i32 [ %29, %24 ], [ 0, %10 ]
%26 = tail call i32 (...) @rand()
%27 = srem i32 %26, %19
%28 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %27)
%29 = add nuw nsw i32 %25, 1
%30 = icmp eq i32 %29, %13
br i1 %30, label %31, label %24
31: ; preds = %24, %10
%32 = tail call i32 @fclose(i32* %22)
%33 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = icmp sgt i32 %16, 0
br i1 %34, label %35, label %40
35: ; preds = %31, %35
%36 = phi i32 [ %38, %35 ], [ 0, %31 ]
%37 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i32 %36, 1
%39 = icmp eq i32 %38, %16
br i1 %39, label %40, label %35
40: ; preds = %35, %31
%41 = tail call i32 @fclose(i32* %33)
br label %42
42: ; preds = %40, %4
%43 = phi i32 [ -1, %4 ], [ 0, %40 ]
ret i32 %43
}