#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 *);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int random2(int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int *, int *);
int main(int argc, char *argv[]) {
  char *months[] = {"jan", "feb", "mar", "apr", "may", "jun",
                    "jul", "aug", "sep", "oct", "nov", "dec"};
  int n_prods, i_month, orderline_id, order_id, prod_id, sales, quan_in_stock;
  char fname[25], line[101];
  FILE *FP_orderlines;
  int *pTot_sales;
  int i_Sys_Type = 0;
  if (argc < 3) {
    printf("syntax:   ds2_create_inv n_prods n_Sys_Type > inv.csv\n");
    printf("n_Sys_Type can be 0 (Linux) or 1 (Windows) \n");
    exit(-1);
  }
  n_prods = atoi(argv[1]);
  i_Sys_Type = atoi(argv[2]);
  pTot_sales = (int *)calloc(n_prods, sizeof(int));
  if (pTot_sales == NULL) {
    printf("Not enough memory\n");
    exit(-1);
  }
  for (prod_id = 0; prod_id < n_prods; prod_id++)
    pTot_sales[prod_id] = 0;
  for (i_month = 0; i_month < 12; i_month++) {
    sprintf(fname, "%s_orderlines.csv", months[i_month]);
    FP_orderlines = fopen(fname, "r");
    while (fgets(line, 100, FP_orderlines)) {
      sscanf(line, "%d,%d,%d,%d", &orderline_id, &order_id, &prod_id, &sales);
      pTot_sales[prod_id - 1] += sales;
    }
  }
  srand(n_prods);
  for (prod_id = 0; prod_id < n_prods; prod_id++) {
    quan_in_stock = random2(0, 500);
    if ((prod_id + 1) % 10000 == 0)
      quan_in_stock *= 10;
    if (i_Sys_Type == 0) {
      printf("%d,%d,%d\n", prod_id + 1, quan_in_stock, pTot_sales[prod_id]);
    } else if (i_Sys_Type == 1) {
      printf("%d,%d,%d\r\n", prod_id + 1, quan_in_stock, pTot_sales[prod_id]);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2bec(%rip),%rsi
mov    $0x60,%edx
call   1070 <memcpy@plt>
movl   $0x0,-0x134(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1218 <main+0x68>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x134(%rbp)
mov    -0x74(%rbp),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x130(%rbp)
cmpq   $0x0,-0x130(%rbp)
jne    1275 <main+0xc5>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    12b7 <main+0x107>
mov    -0x130(%rbp),%rax
movslq -0x84(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    127f <main+0xcf>
movl   $0x0,-0x78(%rbp)
cmpl   $0xc,-0x78(%rbp)
jge    1380 <main+0x1d0>
lea    -0xb0(%rbp),%rdi
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdx
lea    0xdc8(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
lea    0xd18(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     136d <main+0x1bd>
lea    -0x120(%rbp),%rdi
lea    0xd8b(%rip),%rsi
lea    -0x7c(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    -0x84(%rbp),%r8
lea    -0x88(%rbp),%r9
call   1090 <sscanf@plt>
mov    -0x88(%rbp),%edx
mov    -0x130(%rbp),%rax
mov    -0x84(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    %edx,(%rax,%rcx,4)
jmp    12fe <main+0x14e>
jmp    1372 <main+0x1c2>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    12be <main+0x10e>
mov    -0x74(%rbp),%edi
call   1040 <srand@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x74(%rbp),%eax
jge    1473 <main+0x2c3>
xor    %edi,%edi
mov    $0x1f4,%esi
call   1080 <random2@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    13da <main+0x22a>
imul   $0xa,-0x8c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
cmpl   $0x0,-0x134(%rbp)
jne    141a <main+0x26a>
mov    -0x84(%rbp),%esi
add    $0x1,%esi
mov    -0x8c(%rbp),%edx
mov    -0x130(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xcb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    145a <main+0x2aa>
cmpl   $0x1,-0x134(%rbp)
jne    1455 <main+0x2a5>
mov    -0x84(%rbp),%esi
add    $0x1,%esi
mov    -0x8c(%rbp),%edx
mov    -0x130(%rbp),%rax
movslq -0x84(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xc81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    145a <main+0x2aa>
jmp    145f <main+0x2af>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    1392 <main+0x1e2>
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb8,%rsp
cmp    $0x2,%edi
jle    13be <main+0x20e>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
test   %rax,%rax
je     13d3 <main+0x223>
mov    %ebx,0x4(%rsp)
movl   $0x0,(%rsp)
test   %ebp,%ebp
jle    1227 <main+0x77>
xor    %ecx,%ecx
nopl   0x0(%rax)
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    (%rsp),%ecx
add    $0x1,%ecx
mov    %ecx,(%rsp)
cmp    %ebp,%ecx
jl     1210 <main+0x60>
mov    %rax,0x10(%rsp)
mov    %ebp,0x8(%rsp)
xor    %eax,%eax
lea    0x50(%rsp),%r14
jmp    1256 <main+0xa6>
nopl   0x0(%rax)
mov    0x18(%rsp),%rax
add    $0x1,%rax
cmp    $0xc,%rax
mov    %r15,%r14
je     131d <main+0x16d>
mov    %rax,0x18(%rsp)
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
lea    0x30(%rsp),%r15
mov    %r15,%rdi
lea    0xdb8(%rip),%rsi
call   10c0 <sprintf@plt>
mov    %r15,%rdi
lea    0xd83(%rip),%rsi
call   10a0 <fopen@plt>
mov    %r14,%rdi
mov    $0x64,%esi
mov    %rax,0x20(%rsp)
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
lea    0xd97(%rip),%rsi
lea    0x2c(%rsp),%rdx
lea    0x28(%rsp),%rcx
mov    %rsp,%r12
mov    %r14,%r15
lea    0xc(%rsp),%r13
je     1240 <main+0x90>
mov    %r12,%r14
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rsi,%rbp
mov    %rdx,%r12
mov    %r14,%r8
mov    %r13,%r9
mov    %rcx,%rbx
call   1090 <sscanf@plt>
mov    0xc(%rsp),%eax
movslq (%rsp),%rcx
mov    0x10(%rsp),%rdx
add    %eax,-0x4(%rdx,%rcx,4)
mov    %r15,%rdi
mov    $0x64,%esi
mov    0x20(%rsp),%rdx
call   1060 <fgets@plt>
mov    %r12,%rdx
mov    %rbp,%rsi
test   %rax,%rax
mov    %rbx,%rcx
jne    12d0 <main+0x120>
jmp    1240 <main+0x90>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1050 <srand@plt>
movl   $0x0,(%rsp)
test   %ebp,%ebp
mov    0x4(%rsp),%ebx
mov    0x10(%rsp),%r12
jle    13aa <main+0x1fa>
lea    0xd0b(%rip),%r15
lea    0xd0e(%rip),%r14
jmp    136d <main+0x1bd>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    (%r12,%rcx,4),%ecx
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%eax
add    $0x1,%eax
mov    %eax,(%rsp)
cmp    %ebp,%eax
jge    13aa <main+0x1fa>
xor    %edi,%edi
mov    $0x1f4,%esi
call   1080 <random2@plt>
movslq (%rsp),%rcx
lea    0x1(%rcx),%esi
imul   $0x3afb7e91,%esi,%edx
add    $0x346dc0,%edx
ror    $0x4,%edx
cmp    $0x68db9,%edx
jae    139c <main+0x1ec>
add    %eax,%eax
lea    (%rax,%rax,4),%eax
mov    %r15,%rdi
test   %ebx,%ebx
je     1353 <main+0x1a3>
cmp    $0x1,%ebx
je     1350 <main+0x1a0>
jmp    1360 <main+0x1b0>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcb0(%rip),%rdi
call   1030 <puts@plt>
lea    0xcda(%rip),%rdi
jmp    13da <main+0x22a>
lea    0xc89(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"jan\00"
@.str.1 = [4 x i8] c"feb\00"
@.str.2 = [4 x i8] c"mar\00"
@.str.3 = [4 x i8] c"apr\00"
@.str.4 = [4 x i8] c"may\00"
@.str.5 = [4 x i8] c"jun\00"
@.str.6 = [4 x i8] c"jul\00"
@.str.7 = [4 x i8] c"aug\00"
@.str.8 = [4 x i8] c"sep\00"
@.str.9 = [4 x i8] c"oct\00"
@.str.10 = [4 x i8] c"nov\00"
@.str.11 = [4 x i8] c"dec\00"
@__const.main.months = [12 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [55 x i8] c"syntax: ds2_create_inv n_prods n_Sys_Type > inv.csv\0A\00"
@.str.13 = [45 x i8] c"n_Sys_Type can be 0 (Linux) or 1 (Windows) \0A\00"
@.str.14 = [19 x i8] c"Not enough memory\0A\00"
@.str.15 = [18 x i8] c"%s_orderlines.csv\00"
@.str.16 = [2 x i8] c"r\00"
@.str.17 = [12 x i8] c"%d,%d,%d,%d\00"
@.str.18 = [10 x i8] c"%d,%d,%d\0A\00"
@.str.19 = [11 x i8] c"%d,%d,%d\0D\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [12 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [25 x i8]
%15 = alloca [101 x i8]
%16 = alloca i32*
%17 = alloca i32*
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = bitcast [12 x i8*]* %6 to i8*
store i32 0, i32* %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 3
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.12, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %18
%35 = load i32, i32* %7
%36 = call i64 @calloc(i32 %35, i32 4)
%37 = inttoptr i64 %36 to i32*
store i32* %37, i32** %17
%38 = load i32*, i32** %17
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %43
40: ; preds = %26
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.14, i64 0, i64 0))
%42 = call i32 @exit(i32 -1)
unreachable
43: ; preds = %26
store i32 0, i32* %11
br label %44
44: ; preds = %53, %43
%45 = load i32, i32* %11
%46 = load i32, i32* %7
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i32*, i32** %17
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32, i32* %49, i64 %51
store i32 0, i32* %52
br label %53
53: ; preds = %48
%54 = load i32, i32* %11
%55 = add nsw i32 %54, 1
store i32 %55, i32* %11
br label %44
56: ; preds = %44
store i32 0, i32* %8
br label %57
57: ; preds = %86, %56
%58 = load i32, i32* %8
%59 = icmp slt i32 %58, 12
br i1 %59, label %60, label %89
60: ; preds = %57
%61 = getelementptr inbounds [25 x i8], [25 x i8]* %14, i64 0, i64 0
%62 = load i32, i32* %8
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [12 x i8*], [12 x i8*]* %6, i64 0, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @sprintf(i8* %61, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [25 x i8], [25 x i8]* %14, i64 0, i64 0
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
store i32* %68, i32** %16
br label %69
69: ; preds = %74, %60
%70 = getelementptr inbounds [101 x i8], [101 x i8]* %15, i64 0, i64 0
%71 = load i32*, i32** %16
%72 = call i64 @fgets(i8* %70, i32 100, i32* %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %85
74: ; preds = %69
%75 = getelementptr inbounds [101 x i8], [101 x i8]* %15, i64 0, i64 0
%76 = call i32 @sscanf(i8* %75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0), i32* %9, i32* %10, i32* %11, i32* %12)
%77 = load i32, i32* %12
%78 = load i32*, i32** %17
%79 = load i32, i32* %11
%80 = sub nsw i32 %79, 1
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i32, i32* %78, i64 %81
%83 = load i32, i32* %82
%84 = add nsw i32 %83, %77
store i32 %84, i32* %82
br label %69
85: ; preds = %69
br label %86
86: ; preds = %85
%87 = load i32, i32* %8
%88 = add nsw i32 %87, 1
store i32 %88, i32* %8
br label %57
89: ; preds = %57
%90 = load i32, i32* %7
%91 = call i32 @srand(i32 %90)
store i32 0, i32* %11
br label %92
92: ; preds = %133, %89
%93 = load i32, i32* %11
%94 = load i32, i32* %7
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %136
96: ; preds = %92
%97 = call i32 @random2(i32 0, i32 500)
store i32 %97, i32* %13
%98 = load i32, i32* %11
%99 = add nsw i32 %98, 1
%100 = srem i32 %99, 10000
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %96
%103 = load i32, i32* %13
%104 = mul nsw i32 %103, 10
store i32 %104, i32* %13
br label %105
105: ; preds = %102, %96
%106 = load i32, i32* %18
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %105
%109 = load i32, i32* %11
%110 = add nsw i32 %109, 1
%111 = load i32, i32* %13
%112 = load i32*, i32** %17
%113 = load i32, i32* %11
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds i32, i32* %112, i64 %114
%116 = load i32, i32* %115
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), i32 %110, i32 %111, i32 %116)
br label %132
118: ; preds = %105
%119 = load i32, i32* %18
%120 = icmp eq i32 %119, 1
br i1 %120, label %121, label %131
121: ; preds = %118
%122 = load i32, i32* %11
%123 = add nsw i32 %122, 1
%124 = load i32, i32* %13
%125 = load i32*, i32** %17
%126 = load i32, i32* %11
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds i32, i32* %125, i64 %127
%129 = load i32, i32* %128
%130 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0), i32 %123, i32 %124, i32 %129)
br label %131
131: ; preds = %121, %118
br label %132
132: ; preds = %131, %108
br label %133
133: ; preds = %132
%134 = load i32, i32* %11
%135 = add nsw i32 %134, 1
store i32 %135, i32* %11
br label %92
136: ; preds = %92
%137 = load i32, i32* %3
ret i32 %137
}

LLVM IR (-O2):
@.str = [4 x i8] c"jan\00"
@.str.1 = [4 x i8] c"feb\00"
@.str.2 = [4 x i8] c"mar\00"
@.str.3 = [4 x i8] c"apr\00"
@.str.4 = [4 x i8] c"may\00"
@.str.5 = [4 x i8] c"jun\00"
@.str.6 = [4 x i8] c"jul\00"
@.str.7 = [4 x i8] c"aug\00"
@.str.8 = [4 x i8] c"sep\00"
@.str.9 = [4 x i8] c"oct\00"
@.str.10 = [4 x i8] c"nov\00"
@.str.11 = [4 x i8] c"dec\00"
@reltable.main = [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.7 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.8 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.9 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.10 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.11 to i64), i64 ptrtoint ([12 x i32]* @reltable.main to i64)) to i32)]
@.str.15 = [18 x i8] c"%s_orderlines.csv\00"
@.str.16 = [2 x i8] c"r\00"
@.str.17 = [12 x i8] c"%d,%d,%d,%d\00"
@.str.18 = [10 x i8] c"%d,%d,%d\0A\00"
@.str.19 = [11 x i8] c"%d,%d,%d\0D\0A\00"
@str = [18 x i8] c"Not enough memory\00"
@str.20 = [54 x i8] c"syntax: ds2_create_inv n_prods n_Sys_Type > inv.csv\00"
@str.21 = [44 x i8] c"n_Sys_Type can be 0 (Linux) or 1 (Windows) \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [25 x i8]
%8 = alloca [101 x i8]
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = getelementptr inbounds [25 x i8], [25 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [101 x i8], [101 x i8]* %8, i64 0, i64 0
%15 = icmp slt i32 %0, 3
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str.20, i64 0, i64 0))
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.21, i64 0, i64 0))
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @atoi(i8* %25)
%27 = tail call i64 @calloc(i32 %23, i32 4)
%28 = inttoptr i64 %27 to i32*
%29 = icmp eq i64 %27, 0
br i1 %29, label %32, label %30
30: ; preds = %20
store i32 0, i32* %5
%31 = icmp sgt i32 %23, 0
br i1 %31, label %35, label %42
32: ; preds = %20
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %30, %35
%36 = phi i32 [ %40, %35 ], [ 0, %30 ]
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %28, i64 %37
store i32 0, i32* %38
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
%41 = icmp slt i32 %40, %23
br i1 %41, label %35, label %42
42: ; preds = %35, %30
br label %43
43: ; preds = %42, %62
%44 = phi i64 [ %63, %62 ], [ 0, %42 ]
%45 = shl i64 %44, 2
%46 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.main to i8*), i64 %45)
%47 = call i32 @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.15, i64 0, i64 0), i8* %46)
%48 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
%49 = call i64 @fgets(i8* %14, i32 100, i32* %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %62, label %51
51: ; preds = %43, %51
%52 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%53 = load i32, i32* %6
%54 = load i32, i32* %5
%55 = add nsw i32 %54, -1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i32, i32* %28, i64 %56
%58 = load i32, i32* %57
%59 = add nsw i32 %58, %53
store i32 %59, i32* %57
%60 = call i64 @fgets(i8* %14, i32 100, i32* %48)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %51
62: ; preds = %51, %43
%63 = add nuw nsw i64 %44, 1
%64 = icmp eq i64 %63, 12
br i1 %64, label %65, label %43
65: ; preds = %62
%66 = call i32 @srand(i32 %23)
store i32 0, i32* %5
br i1 %31, label %67, label %86
67: ; preds = %65, %82
%68 = call i32 @random2(i32 0, i32 500)
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
%71 = srem i32 %70, 10000
%72 = icmp eq i32 %71, 0
%73 = mul nsw i32 %68, 10
%74 = select i1 %72, i32 %73, i32 %68
switch i32 %26, label %82 [
i32 0, label %76
i32 1, label %75
]
75: ; preds = %67
br label %76
76: ; preds = %67, %75
%77 = phi i8* [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.19, i64 0, i64 0), %75 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.18, i64 0, i64 0), %67 ]
%78 = sext i32 %69 to i64
%79 = getelementptr inbounds i32, i32* %28, i64 %78
%80 = load i32, i32* %79
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %77, i32 %70, i32 %74, i32 %80)
br label %82
82: ; preds = %76, %67
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
%85 = icmp slt i32 %84, %23
br i1 %85, label %67, label %86
86: ; preds = %82, %65
ret i32 0
}