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

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int i, j, num, candidat;
  int matriu[100][100];
  int repetits[100] = {0};
  do {
    printf("Introdueix la dimensió de la matriu 1-%d: ", 100);
    scanf("%d", &num);
  } while (num < 1 || num > 100);
  srandom(time(0));
  for (i = 0; i < num; i++) {
    for (j = 0; j < num; j++) {
      do {
        candidat = random() % (num * num);
      } while (repetits[candidat] != 0);
      repetits[candidat]++;
      printf("%4d", matriu[i][j] = candidat + 1);
    }
    printf("\n");
  }
  printf("\n");
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9e00,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x9df0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1050 <memset@plt>
lea    0xe6d(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe86(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <scanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x1c(%rbp)
mov    %al,-0x9df1(%rbp)
jl     11ce <main+0x6e>
cmpl   $0x64,-0x1c(%rbp)
setg   %al
mov    %al,-0x9df1(%rbp)
mov    -0x9df1(%rbp),%al
test   $0x1,%al
jne    118c <main+0x2c>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12aa <main+0x14a>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    128e <main+0x12e>
jmp    1215 <main+0xb5>
mov    $0x0,%al
call   1070 <random@plt>
mov    -0x1c(%rbp),%ecx
imul   -0x1c(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmpl   $0x0,-0x9df0(%rbp,%rax,4)
jne    1215 <main+0xb5>
movslq -0x20(%rbp),%rax
mov    -0x9df0(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x9df0(%rbp,%rax,4)
mov    -0x20(%rbp),%esi
add    $0x1,%esi
movslq -0x14(%rbp),%rcx
lea    -0x9c60(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
mov    %esi,(%rax,%rcx,4)
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1204 <main+0xa4>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f1 <main+0x91>
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%eax
add    $0x9e00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1a8,%rsp
lea    0x10(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xe6b(%rip),%r14
lea    0xe90(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffff9b,%eax
cmp    $0xffffff9c,%eax
jb     11b0 <main+0x40>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srandom@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    125b <main+0xeb>
lea    0xe3c(%rip),%rbx
xor    %r14d,%r14d
jmp    1217 <main+0xa7>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r14d
mov    0xc(%rsp),%eax
cmp    %eax,%r14d
jge    125b <main+0xeb>
test   %eax,%eax
jle    1200 <main+0x90>
xor    %ebp,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1080 <random@plt>
mov    0xc(%rsp),%ecx
imul   %ecx,%ecx
cltd
idiv   %ecx
movslq %edx,%rsi
cmpl   $0x0,0x10(%rsp,%rsi,4)
jne    1220 <main+0xb0>
movl   $0x1,0x10(%rsp,%rsi,4)
add    $0x1,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     1220 <main+0xb0>
jmp    1200 <main+0x90>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Introdueix la dimensi\C3\B3 de la matriu 1-%d: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%4d\00"
@.str.3 = [2 x i8] c"\0A\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 [100 x [100 x i32]]
%11 = alloca [100 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [100 x i32]* %11 to i8*
br label %13
13: ; preds = %22, %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 100)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
br label %16
16: ; preds = %13
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 1
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* %8
%21 = icmp sgt i32 %20, 100
br label %22
22: ; preds = %19, %16
%23 = phi i1 [ true, %16 ], [ %21, %19 ]
br i1 %23, label %13, label %24
24: ; preds = %22
%25 = call i32 @time(i32 0)
%26 = call i32 @srandom(i32 %25)
store i32 0, i32* %6
br label %27
27: ; preds = %69, %24
%28 = load i32, i32* %6
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %72
31: ; preds = %27
store i32 0, i32* %7
br label %32
32: ; preds = %64, %31
%33 = load i32, i32* %7
%34 = load i32, i32* %8
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %67
36: ; preds = %32
br label %37
37: ; preds = %43, %36
%38 = call i32 (...) @random()
%39 = load i32, i32* %8
%40 = load i32, i32* %8
%41 = mul nsw i32 %39, %40
%42 = srem i32 %38, %41
store i32 %42, i32* %9
br label %43
43: ; preds = %37
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %11, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %37, label %49
49: ; preds = %43
%50 = load i32, i32* %9
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %11, i64 0, i64 %51
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
%57 = load i32, i32* %6
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %10, i64 0, i64 %58
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [100 x i32], [100 x i32]* %59, i64 0, i64 %61
store i32 %56, i32* %62
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %56)
br label %64
64: ; preds = %49
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %7
br label %32
67: ; preds = %32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %69
69: ; preds = %67
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %27
72: ; preds = %27
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}

LLVM IR (-O2):
@.str = [44 x i8] c"Introdueix la dimensi\C3\B3 de la matriu 1-%d: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%4d\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [100 x i32]* %4 to i8*
br label %7
7: ; preds = %7, %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i32 100)
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = add i32 %10, -101
%12 = icmp ult i32 %11, -100
br i1 %12, label %7, label %13
13: ; preds = %7
%14 = call i32 @time(i32 0)
%15 = call i32 @srandom(i32 %14)
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %45
18: ; preds = %13, %40
%19 = phi i32 [ %43, %40 ], [ %16, %13 ]
%20 = phi i32 [ %42, %40 ], [ 0, %13 ]
%21 = icmp sgt i32 %19, 0
br i1 %21, label %22, label %40
22: ; preds = %18, %33
%23 = phi i32 [ %37, %33 ], [ 0, %18 ]
br label %24
24: ; preds = %22, %24
%25 = call i32 (...) @random()
%26 = load i32, i32* %3
%27 = mul nsw i32 %26, %26
%28 = srem i32 %25, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %24
33: ; preds = %24
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %29
store i32 1, i32* %34
%35 = add nsw i32 %28, 1
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = add nuw nsw i32 %23, 1
%38 = load i32, i32* %3
%39 = icmp slt i32 %37, %38
br i1 %39, label %22, label %40
40: ; preds = %33, %18
%41 = call i32 @putchar(i32 10)
%42 = add nuw nsw i32 %20, 1
%43 = load i32, i32* %3
%44 = icmp slt i32 %42, %43
br i1 %44, label %18, label %45
45: ; preds = %40, %13
%46 = call i32 @putchar(i32 10)
%47 = load i32, i32* @EXIT_SUCCESS
ret i32 %47
}