#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 */
float pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
float sqrt(float);
int main() {
  int mat[100][100], i, j, n, trace = 0;
  float norm = 0.0;
  printf("enter order of the matrix");
  scanf("%d", &n);
  printf("enter the matrix elements row-wise\n");
  for (i = 0; i < n; i++)
    for (j = 0; j < n; j++) {
      scanf("%d", &mat[i][j]);
      norm = norm + pow(mat[i][j], 2);
      if (i == j)
        trace = trace + mat[i][j];
    }
  norm = sqrt(norm);
  printf("\nnorm=%f\ntrace=%d\n", norm, trace);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x9c70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x9c60(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x9c64(%rbp)
ff
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x9c5c(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x9c54(%rbp)
mov    -0x9c54(%rbp),%eax
cmp    -0x9c5c(%rbp),%eax
jge    12c5 <main+0x185>
movl   $0x0,-0x9c58(%rbp)
mov    -0x9c58(%rbp),%eax
cmp    -0x9c5c(%rbp),%eax
jge    12ac <main+0x16c>
movslq -0x9c54(%rbp),%rax
lea    -0x9c50(%rbp),%rsi
imul   $0x190,%rax,%rax
add    %rax,%rsi
movslq -0x9c58(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1f(%rip),%rdi
call   1040 <scanf@plt>
movss  -0x9c64(%rbp),%xmm0
ff
movss  %xmm0,-0x9c68(%rbp)
ff
movslq -0x9c54(%rbp),%rcx
lea    -0x9c50(%rbp),%rax
imul   $0x190,%rcx,%rcx
add    %rcx,%rax
movslq -0x9c58(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
mov    $0x2,%esi
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movss  -0x9c68(%rbp),%xmm0
ff
addss  %xmm1,%xmm0
movss  %xmm0,-0x9c64(%rbp)
ff
mov    -0x9c54(%rbp),%eax
cmp    -0x9c58(%rbp),%eax
jne    1293 <main+0x153>
mov    -0x9c60(%rbp),%eax
movslq -0x9c54(%rbp),%rdx
lea    -0x9c50(%rbp),%rcx
imul   $0x190,%rdx,%rdx
add    %rdx,%rcx
movslq -0x9c58(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x9c60(%rbp)
jmp    1298 <main+0x158>
mov    -0x9c58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c58(%rbp)
jmp    11bc <main+0x7c>
jmp    12b1 <main+0x171>
mov    -0x9c54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9c54(%rbp)
jmp    11a0 <main+0x60>
movss  -0x9c64(%rbp),%xmm0
ff
call   1060 <sqrt@plt>
movss  %xmm0,-0x9c64(%rbp)
ff
movss  -0x9c64(%rbp),%xmm0
ff
cvtss2sd %xmm0,%xmm0
mov    -0x9c60(%rbp),%esi
lea    0xd4e(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x9c70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x9c58,%rsp
lea    0xe9c(%rip),%rdi
xor    %r15d,%r15d
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea5(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    0xc(%rsp),%eax
xorps  %xmm1,%xmm1
test   %eax,%eax
jle    1223 <main+0xd3>
xor    %r13d,%r13d
xorps  %xmm1,%xmm1
lea    0x10(%rsp),%r12
lea    0xe6e(%rip),%r14
xor    %r15d,%r15d
jmp    11d3 <main+0x83>
cs nopw 0x0(%rax,%rax,1)
nop
movslq %eax,%rcx
add    $0x1,%r13
add    $0x190,%r12
cmp    %rcx,%r13
jge    1223 <main+0xd3>
test   %eax,%eax
jle    11c0 <main+0x70>
mov    %r12,%rbx
xor    %ebp,%ebp
jmp    11fc <main+0xac>
xchg   %ax,%ax
movss  0x8(%rsp),%xmm1
addss  %xmm0,%xmm1
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jge    11c0 <main+0x70>
movss  %xmm1,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    (%rbx),%edi
mov    $0x2,%esi
call   1060 <pow@plt>
cmp    %rbp,%r13
jne    11e0 <main+0x90>
add    (%rbx),%r15d
jmp    11e0 <main+0x90>
ucomiss 0xdd6(%rip),%xmm1
jb     1235 <main+0xe5>
xorps  %xmm0,%xmm0
sqrtss %xmm1,%xmm0
jmp    123d <main+0xed>
movaps %xmm1,%xmm0
call   1070 <sqrt@plt>
cvtss2sd %xmm0,%xmm0
lea    0xdd9(%rip),%rdi
mov    %r15d,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x9c58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"enter order of the matrix\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [36 x i8] c"enter the matrix elements row-wise\0A\00"
@.str.3 = [19 x i8] c"\0Anorm=%f\0Atrace=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x [100 x i32]]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca float
store i32 0, i32* %1
store i32 0, i32* %6
store float 0.000000e+00, float* %7
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %11
11: ; preds = %56, %0
%12 = load i32, i32* %3
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %59
15: ; preds = %11
store i32 0, i32* %4
br label %16
16: ; preds = %52, %15
%17 = load i32, i32* %4
%18 = load i32, i32* %5
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %55
20: ; preds = %16
%21 = load i32, i32* %3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %22
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i32], [100 x i32]* %23, i64 0, i64 %25
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %26)
%28 = load float, float* %7
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %30
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i32], [100 x i32]* %31, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = call float @pow(i32 %35, i32 2)
%37 = fadd float %28, %36
store float %37, float* %7
%38 = load i32, i32* %3
%39 = load i32, i32* %4
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %20
%42 = load i32, i32* %6
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %2, i64 0, i64 %44
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x i32], [100 x i32]* %45, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = add nsw i32 %42, %49
store i32 %50, i32* %6
br label %51
51: ; preds = %41, %20
br label %52
52: ; preds = %51
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %16
55: ; preds = %16
br label %56
56: ; preds = %55
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %11
59: ; preds = %11
%60 = load float, float* %7
%61 = call float @sqrt(float %60)
store float %61, float* %7
%62 = load float, float* %7
%63 = fpext float %62 to double
%64 = load i32, i32* %6
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %63, i32 %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"enter order of the matrix\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [19 x i8] c"\0Anorm=%f\0Atrace=%d\0A\00"
@str = [35 x i8] c"enter the matrix elements row-wise\00"
define i32 @main() {
%1 = alloca [100 x [100 x i32]]
%2 = alloca i32
%3 = bitcast [100 x [100 x i32]]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %0, %35
%11 = phi i32 [ %36, %35 ], [ %8, %0 ]
%12 = phi i64 [ %40, %35 ], [ 0, %0 ]
%13 = phi float [ %38, %35 ], [ 0.000000e+00, %0 ]
%14 = phi i32 [ %37, %35 ], [ 0, %0 ]
%15 = icmp sgt i32 %11, 0
br i1 %15, label %16, label %35
16: ; preds = %10, %29
%17 = phi i64 [ %31, %29 ], [ 0, %10 ]
%18 = phi float [ %24, %29 ], [ %13, %10 ]
%19 = phi i32 [ %30, %29 ], [ %14, %10 ]
%20 = getelementptr inbounds [100 x [100 x i32]], [100 x [100 x i32]]* %1, i64 0, i64 %12, i64 %17
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
%22 = load i32, i32* %20
%23 = call float @pow(i32 %22, i32 2)
%24 = fadd float %18, %23
%25 = icmp eq i64 %12, %17
br i1 %25, label %26, label %29
26: ; preds = %16
%27 = load i32, i32* %20
%28 = add nsw i32 %27, %19
br label %29
29: ; preds = %16, %26
%30 = phi i32 [ %28, %26 ], [ %19, %16 ]
%31 = add nuw nsw i64 %17, 1
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %16, label %35
35: ; preds = %29, %10
%36 = phi i32 [ %11, %10 ], [ %32, %29 ]
%37 = phi i32 [ %14, %10 ], [ %30, %29 ]
%38 = phi float [ %13, %10 ], [ %24, %29 ]
%39 = sext i32 %36 to i64
%40 = add nuw nsw i64 %12, 1
%41 = icmp slt i64 %40, %39
br i1 %41, label %10, label %42
42: ; preds = %35, %0
%43 = phi i32 [ 0, %0 ], [ %37, %35 ]
%44 = phi float [ 0.000000e+00, %0 ], [ %38, %35 ]
%45 = call float @sqrt(float %44)
%46 = fpext float %45 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), double %46, i32 %43)
ret i32 0
}