#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ generate_matrices(int /*<<< orphan*/ *, int, int, int, int,
                                     int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(void) {
  FILE *f;
  int nra, nca, nrb, ncb, seed, limit;
  if (!(f = fopen("matrices.dat", "w"))) {
    perror("Cannot create file");
    exit(1);
  }
  printf("Give dimensions of the matrices (row, column, row and column): ");
  scanf("%d %d %d %d", &nra, &nca, &nrb, &ncb);
  printf("Enter random seed: ");
  scanf("%d", &seed);
  printf("Enter element value limit: ");
  scanf("%d", &limit);
  generate_matrices(f, nra, nca, nrb, ncb, seed, limit);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11b6 <main+0x46>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
lea    0xe78(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
lea    0xe5a(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0x20(%rbp),%r8d
mov    -0x24(%rbp),%r9d
mov    -0x28(%rbp),%eax
mov    %eax,(%rsp)
call   1090 <generate_matrices@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe82(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1238 <main+0xc8>
mov    %rax,%rbx
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    0x24(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x18(%rsp),%r8
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
lea    0xe94(%rip),%r14
lea    0x14(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x24(%rsp),%esi
mov    0x20(%rsp),%edx
mov    0x1c(%rsp),%ecx
mov    0x18(%rsp),%r8d
mov    0x14(%rsp),%r9d
mov    0x10(%rsp),%eax
mov    %eax,(%rsp)
mov    %rbx,%rdi
call   1090 <generate_matrices@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdd0(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"matrices.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"Cannot create file\00"
@.str.3 = [64 x i8] c"Give dimensions of the matrices (row, column, row and column): \00"
@.str.4 = [12 x i8] c"%d %d %d %d\00"
@.str.5 = [20 x i8] c"Enter random seed: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [28 x i8] c"Enter element value limit: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32* %4, i32* %5, i32* %6)
%17 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %7)
%19 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %8)
%21 = load i32*, i32** %2
%22 = load i32, i32* %3
%23 = load i32, i32* %4
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = call i32 @generate_matrices(i32* %21, i32 %22, i32 %23, i32 %24, i32 %25, i32 %26, i32 %27)
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"matrices.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"Cannot create file\00"
@.str.3 = [64 x i8] c"Give dimensions of the matrices (row, column, row and column): \00"
@.str.4 = [12 x i8] c"%d %d %d %d\00"
@.str.5 = [20 x i8] c"Enter random seed: \00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [28 x i8] c"Enter element value limit: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to 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 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %0
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %2, i32* %3, i32* %4)
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%22 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%23 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %6)
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @generate_matrices(i32* %13, i32 %25, i32 %26, i32 %27, i32 %28, i32 %29, i32 %30)
%32 = call i32 @fclose(i32* %13)
ret i32 0
}