#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 */
char EOF;
int EXIT_SUCCESS;
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ puts(char *);
int scanf(char *, int *);
int sumArray(int *, int, int);
int main(void) {
  int nums[16] = {0};
  int isInputValid = 0;
  int diagSum1 = 0;
  int diagSum2 = 0;
  int rowSum = 0;
  int colSum = 0;
  int col = 0;
  int row = 0;
  printf("Enter the numbers from 1 to %d in any order:\n", 16);
  while (!isInputValid) {
    int i = 0;
    while (i < 16) {
      if (scanf("%d", &nums[i]) < 1) {
        char c = '\0';
        while ((c = getchar()) != '\n' && c != EOF) {
          continue;
        }
        isInputValid = 0;
        break;
      };
      isInputValid = 1;
      ++i;
    }
    if (!isInputValid)
      puts("Input invalid. Please try again.");
  }
  getchar();
  int i = 0;
  while (i < 16) {
    if ((i > 0) && ((i % 4) == 0)) {
      putchar('\n');
    }
    printf("%2d ", nums[i]);
    ++i;
  }
  putchar('\n');
  printf("Row sums: ");
  for (row = 0; row < (16 / 4); ++row) {
    rowSum = sumArray(&nums[row * 4], 4, 1);
    printf("%d ", rowSum);
  }
  putchar('\n');
  printf("Column sums: ");
  for (col = 0; col < 4; ++col) {
    colSum = sumArray(&nums[col], 16, 4);
    printf("%d ", colSum);
  }
  putchar('\n');
  i = 0;
  row = 0;
  col = 0;
  while (i < 16) {
    if (col == row) {
      diagSum1 += nums[i];
    }
    if (col + row == 4 - 1) {
      diagSum2 += nums[i];
    }
    col = (col + 1) % 4;
    if (col == 0) {
      ++row;
    }
    ++i;
  }
  printf("Diagonal sums: %d %d\n", diagSum1, diagSum2);
  getchar();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x10,%esi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x54(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ec <main+0x7c>
jmp    12a7 <main+0x137>
movl   $0x0,-0x70(%rbp)
cmpl   $0x10,-0x70(%rbp)
jge    128c <main+0x11c>
movslq -0x70(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe1b(%rip),%rdi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jge    1277 <main+0x107>
movb   $0x0,-0x71(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x79(%rbp)
je     1256 <main+0xe6>
movsbl -0x71(%rbp),%eax
mov    0x2d9d(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x79(%rbp)
mov    -0x79(%rbp),%al
test   $0x1,%al
jne    1266 <main+0xf6>
jmp    126b <main+0xfb>
jmp    1225 <main+0xb5>
movl   $0x0,-0x54(%rbp)
jmp    128c <main+0x11c>
movl   $0x1,-0x54(%rbp)
mov    -0x70(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x70(%rbp)
jmp    11f3 <main+0x83>
cmpl   $0x0,-0x54(%rbp)
jne    12a2 <main+0x132>
lea    0xd94(%rip),%rdi
call   1040 <puts@plt>
jmp    11d6 <main+0x66>
mov    $0x0,%al
call   1080 <getchar@plt>
movl   $0x0,-0x78(%rbp)
cmpl   $0x10,-0x78(%rbp)
jge    130b <main+0x19b>
cmpl   $0x0,-0x78(%rbp)
jle    12e7 <main+0x177>
mov    -0x78(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12e7 <main+0x177>
mov    $0xa,%edi
call   1030 <putchar@plt>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%esi
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    12b5 <main+0x145>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x6c(%rbp)
cmpl   $0x4,-0x6c(%rbp)
jge    1378 <main+0x208>
mov    -0x6c(%rbp),%eax
shl    $0x2,%eax
cltq
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <sumArray@plt>
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%esi
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
jmp    132a <main+0x1ba>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x68(%rbp)
cmpl   $0x4,-0x68(%rbp)
jge    13e1 <main+0x271>
movslq -0x68(%rbp),%rax
lea    -0x50(%rbp),%rdi
shl    $0x2,%rax
add    %rax,%rdi
mov    $0x10,%esi
mov    $0x4,%edx
call   1050 <sumArray@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%esi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1397 <main+0x227>
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x78(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x0,-0x68(%rbp)
cmpl   $0x10,-0x78(%rbp)
jge    1473 <main+0x303>
mov    -0x68(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jne    1424 <main+0x2b4>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
add    -0x58(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x68(%rbp),%eax
add    -0x6c(%rbp),%eax
cmp    $0x3,%eax
jne    1441 <main+0x2d1>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
add    -0x5c(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jne    1465 <main+0x2f5>
mov    -0x6c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1400 <main+0x290>
mov    -0x58(%rbp),%esi
mov    -0x5c(%rbp),%edx
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
mov    0x2b43(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe75(%rip),%rdi
mov    $0x10,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rbx
lea    0x8(%rsp),%rbp
lea    0xe86(%rip),%r14
mov    %rsp,%r15
mov    0x2e36(%rip),%r12
lea    0xe78(%rip),%r13
jmp    11c8 <main+0x68>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0xc(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x14(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x18(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x1c(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x20(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x24(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x28(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x2c(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x30(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x34(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x38(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jle    1300 <main+0x1a0>
mov    %r14,%rdi
lea    0x3c(%rsp),%rsi
call   1080 <scanf@plt>
test   %eax,%eax
jg     131a <main+0x1ba>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
je     11c0 <main+0x60>
cmp    (%r12),%al
jne    1300 <main+0x1a0>
jmp    11c0 <main+0x60>
xor    %eax,%eax
call   1070 <getchar@plt>
lea    0xd2a(%rip),%rbx
xor    %ebp,%ebp
jmp    1347 <main+0x1e7>
nopl   0x0(%rax)
mov    (%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1362 <main+0x202>
test   %rbp,%rbp
je     1330 <main+0x1d0>
mov    %ebp,%eax
and    $0x3,%eax
test   %rax,%rax
jne    1330 <main+0x1d0>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1330 <main+0x1d0>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xce4(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <sumArray@plt>
lea    0xcca(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x10(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x20(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xc51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    $0x10,%esi
mov    $0x4,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x4(%rsp),%rdi
mov    $0x10,%esi
mov    $0x4,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0x10,%esi
mov    $0x4,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc(%rsp),%rdi
mov    $0x10,%esi
mov    $0x4,%edx
call   1050 <sumArray@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
xor    %ecx,%ecx
xor    %edx,%edx
xor    %esi,%esi
jmp    14d3 <main+0x373>
xchg   %ax,%ax
lea    0x1(%rcx),%edi
add    $0x4,%ecx
test   %edi,%edi
cmovns %edi,%ecx
and    $0xfffffffc,%ecx
xor    %ebx,%ebx
sub    %ecx,%edi
sete   %bl
add    %ebx,%eax
add    $0x1,%rbp
mov    %edi,%ecx
cmp    $0x10,%rbp
je     14e7 <main+0x387>
cmp    %eax,%ecx
jne    14da <main+0x37a>
add    (%rsp,%rbp,4),%esi
lea    (%rax,%rcx,1),%edi
cmp    $0x3,%edi
jne    14b0 <main+0x350>
add    (%rsp,%rbp,4),%edx
jmp    14b0 <main+0x350>
lea    0xb86(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    0x2ad5(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [46 x i8] c"Enter the numbers from 1 to %d in any order:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i8 0
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.3 = [5 x i8] c"%2d \00"
@.str.4 = [11 x i8] c"Row sums: \00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [14 x i8] c"Column sums: \00"
@.str.7 = [22 x i8] c"Diagonal sums: %d %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
store i32 0, i32* %1
%13 = bitcast [16 x i32]* %2 to i8*
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 16)
br label %15
15: ; preds = %52, %0
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %53
19: ; preds = %15
store i32 0, i32* %10
br label %20
20: ; preds = %44, %19
%21 = load i32, i32* %10
%22 = icmp slt i32 %21, 16
br i1 %22, label %23, label %47
23: ; preds = %20
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16 x i32], [16 x i32]* %2, 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 = icmp slt i32 %27, 1
br i1 %28, label %29, label %44
29: ; preds = %23
store i8 0, i8* %11
br label %30
30: ; preds = %42, %29
%31 = call signext i8 (...) @getchar()
store i8 %31, i8* %11
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i8, i8* %11
%36 = sext i8 %35 to i32
%37 = load i8, i8* @EOF
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %36, %38
br label %40
40: ; preds = %34, %30
%41 = phi i1 [ false, %30 ], [ %39, %34 ]
br i1 %41, label %42, label %43
42: ; preds = %40
br label %30
43: ; preds = %40
store i32 0, i32* %3
br label %47
44: ; preds = %23
store i32 1, i32* %3
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
br label %20
47: ; preds = %43, %20
%48 = load i32, i32* %3
%49 = icmp ne i32 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = call i32 @puts(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %47
br label %15
53: ; preds = %15
%54 = call signext i8 (...) @getchar()
store i32 0, i32* %12
br label %55
55: ; preds = %67, %53
%56 = load i32, i32* %12
%57 = icmp slt i32 %56, 16
br i1 %57, label %58, label %75
58: ; preds = %55
%59 = load i32, i32* %12
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %58
%62 = load i32, i32* %12
%63 = srem i32 %62, 4
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %61
%66 = call i32 @putchar(i8 signext 10)
br label %67
67: ; preds = %65, %61, %58
%68 = load i32, i32* %12
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %69
%71 = load i32, i32* %70
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %71)
%73 = load i32, i32* %12
%74 = add nsw i32 %73, 1
store i32 %74, i32* %12
br label %55
75: ; preds = %55
%76 = call i32 @putchar(i8 signext 10)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %9
br label %78
78: ; preds = %89, %75
%79 = load i32, i32* %9
%80 = icmp slt i32 %79, 4
br i1 %80, label %81, label %92
81: ; preds = %78
%82 = load i32, i32* %9
%83 = mul nsw i32 %82, 4
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %84
%86 = call i32 @sumArray(i32* %85, i32 4, i32 1)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %87)
br label %89
89: ; preds = %81
%90 = load i32, i32* %9
%91 = add nsw i32 %90, 1
store i32 %91, i32* %9
br label %78
92: ; preds = %78
%93 = call i32 @putchar(i8 signext 10)
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %8
br label %95
95: ; preds = %105, %92
%96 = load i32, i32* %8
%97 = icmp slt i32 %96, 4
br i1 %97, label %98, label %108
98: ; preds = %95
%99 = load i32, i32* %8
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %100
%102 = call i32 @sumArray(i32* %101, i32 16, i32 4)
store i32 %102, i32* %7
%103 = load i32, i32* %7
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %103)
br label %105
105: ; preds = %98
%106 = load i32, i32* %8
%107 = add nsw i32 %106, 1
store i32 %107, i32* %8
br label %95
108: ; preds = %95
%109 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %12
store i32 0, i32* %9
store i32 0, i32* %8
br label %110
110: ; preds = %145, %108
%111 = load i32, i32* %12
%112 = icmp slt i32 %111, 16
br i1 %112, label %113, label %148
113: ; preds = %110
%114 = load i32, i32* %8
%115 = load i32, i32* %9
%116 = icmp eq i32 %114, %115
br i1 %116, label %117, label %124
117: ; preds = %113
%118 = load i32, i32* %12
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %119
%121 = load i32, i32* %120
%122 = load i32, i32* %4
%123 = add nsw i32 %122, %121
store i32 %123, i32* %4
br label %124
124: ; preds = %117, %113
%125 = load i32, i32* %8
%126 = load i32, i32* %9
%127 = add nsw i32 %125, %126
%128 = icmp eq i32 %127, 3
br i1 %128, label %129, label %136
129: ; preds = %124
%130 = load i32, i32* %12
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [16 x i32], [16 x i32]* %2, i64 0, i64 %131
%133 = load i32, i32* %132
%134 = load i32, i32* %5
%135 = add nsw i32 %134, %133
store i32 %135, i32* %5
br label %136
136: ; preds = %129, %124
%137 = load i32, i32* %8
%138 = add nsw i32 %137, 1
%139 = srem i32 %138, 4
store i32 %139, i32* %8
%140 = load i32, i32* %8
%141 = icmp eq i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %136
%143 = load i32, i32* %9
%144 = add nsw i32 %143, 1
store i32 %144, i32* %9
br label %145
145: ; preds = %142, %136
%146 = load i32, i32* %12
%147 = add nsw i32 %146, 1
store i32 %147, i32* %12
br label %110
148: ; preds = %110
%149 = load i32, i32* %4
%150 = load i32, i32* %5
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %149, i32 %150)
%152 = call signext i8 (...) @getchar()
%153 = load i32, i32* @EXIT_SUCCESS
ret i32 %153
}

LLVM IR (-O2):
@.str = [46 x i8] c"Enter the numbers from 1 to %d in any order:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@EOF = global i8 0
@.str.2 = [33 x i8] c"Input invalid. Please try again.\00"
@.str.3 = [5 x i8] c"%2d \00"
@.str.4 = [11 x i8] c"Row sums: \00"
@.str.5 = [4 x i8] c"%d \00"
@.str.6 = [14 x i8] c"Column sums: \00"
@.str.7 = [22 x i8] c"Diagonal sums: %d %d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [16 x i32]
%2 = bitcast [16 x i32]* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 16)
%4 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 15
%5 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 0
%6 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 1
%7 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 2
%8 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 3
%9 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 4
%10 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 5
%11 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 6
%12 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 7
%13 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 8
%14 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 9
%15 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 10
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 11
%17 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 12
%18 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 13
%19 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 14
br label %20
20: ; preds = %75, %0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%22 = icmp slt i32 %21, 1
br i1 %22, label %68, label %23
23: ; preds = %20
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %6)
%25 = icmp slt i32 %24, 1
br i1 %25, label %68, label %26
26: ; preds = %23
%27 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%28 = icmp slt i32 %27, 1
br i1 %28, label %68, label %29
29: ; preds = %26
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%31 = icmp slt i32 %30, 1
br i1 %31, label %68, label %32
32: ; preds = %29
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%34 = icmp slt i32 %33, 1
br i1 %34, label %68, label %35
35: ; preds = %32
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %10)
%37 = icmp slt i32 %36, 1
br i1 %37, label %68, label %38
38: ; preds = %35
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%40 = icmp slt i32 %39, 1
br i1 %40, label %68, label %41
41: ; preds = %38
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %12)
%43 = icmp slt i32 %42, 1
br i1 %43, label %68, label %44
44: ; preds = %41
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %13)
%46 = icmp slt i32 %45, 1
br i1 %46, label %68, label %47
47: ; preds = %44
%48 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%49 = icmp slt i32 %48, 1
br i1 %49, label %68, label %50
50: ; preds = %47
%51 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %15)
%52 = icmp slt i32 %51, 1
br i1 %52, label %68, label %53
53: ; preds = %50
%54 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%55 = icmp slt i32 %54, 1
br i1 %55, label %68, label %56
56: ; preds = %53
%57 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%58 = icmp slt i32 %57, 1
br i1 %58, label %68, label %59
59: ; preds = %56
%60 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%61 = icmp slt i32 %60, 1
br i1 %61, label %68, label %62
62: ; preds = %59
%63 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%64 = icmp slt i32 %63, 1
br i1 %64, label %68, label %65
65: ; preds = %62
%66 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%67 = icmp slt i32 %66, 1
br i1 %67, label %68, label %77
68: ; preds = %65, %62, %59, %56, %53, %50, %47, %44, %41, %38, %35, %32, %29, %26, %23, %20
br label %69
69: ; preds = %68, %69
%70 = call signext i8 (...) @getchar()
%71 = icmp ne i8 %70, 10
%72 = load i8, i8* @EOF
%73 = icmp ne i8 %70, %72
%74 = select i1 %71, i1 %73, i1 false
br i1 %74, label %69, label %75
75: ; preds = %69
%76 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %20
77: ; preds = %65
%78 = call signext i8 (...) @getchar()
br label %79
79: ; preds = %77, %87
%80 = phi i64 [ 0, %77 ], [ %91, %87 ]
%81 = icmp ne i64 %80, 0
%82 = and i64 %80, 3
%83 = icmp eq i64 %82, 0
%84 = and i1 %81, %83
br i1 %84, label %85, label %87
85: ; preds = %79
%86 = call i32 @putchar(i8 signext 10)
br label %87
87: ; preds = %85, %79
%88 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 %80
%89 = load i32, i32* %88
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %89)
%91 = add nuw nsw i64 %80, 1
%92 = icmp eq i64 %91, 16
br i1 %92, label %93, label %79
93: ; preds = %87
%94 = call i32 @putchar(i8 signext 10)
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%96 = call i32 @sumArray(i32* %5, i32 4, i32 1)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %96)
%98 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 4
%99 = call i32 @sumArray(i32* %98, i32 4, i32 1)
%100 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %99)
%101 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 8
%102 = call i32 @sumArray(i32* %101, i32 4, i32 1)
%103 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %102)
%104 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 12
%105 = call i32 @sumArray(i32* %104, i32 4, i32 1)
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %105)
%107 = call i32 @putchar(i8 signext 10)
%108 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%109 = call i32 @sumArray(i32* %5, i32 16, i32 4)
%110 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %109)
%111 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 1
%112 = call i32 @sumArray(i32* %111, i32 16, i32 4)
%113 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %112)
%114 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 2
%115 = call i32 @sumArray(i32* %114, i32 16, i32 4)
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %115)
%117 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 3
%118 = call i32 @sumArray(i32* %117, i32 16, i32 4)
%119 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %118)
%120 = call i32 @putchar(i8 signext 10)
br label %121
121: ; preds = %93, %140
%122 = phi i64 [ 0, %93 ], [ %147, %140 ]
%123 = phi i32 [ 0, %93 ], [ %146, %140 ]
%124 = phi i32 [ 0, %93 ], [ %143, %140 ]
%125 = phi i32 [ 0, %93 ], [ %141, %140 ]
%126 = phi i32 [ 0, %93 ], [ %133, %140 ]
%127 = icmp eq i32 %124, %123
br i1 %127, label %128, label %132
128: ; preds = %121
%129 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 %122
%130 = load i32, i32* %129
%131 = add nsw i32 %130, %126
br label %132
132: ; preds = %128, %121
%133 = phi i32 [ %131, %128 ], [ %126, %121 ]
%134 = add nsw i32 %123, %124
%135 = icmp eq i32 %134, 3
br i1 %135, label %136, label %140
136: ; preds = %132
%137 = getelementptr inbounds [16 x i32], [16 x i32]* %1, i64 0, i64 %122
%138 = load i32, i32* %137
%139 = add nsw i32 %138, %125
br label %140
140: ; preds = %136, %132
%141 = phi i32 [ %139, %136 ], [ %125, %132 ]
%142 = add nsw i32 %124, 1
%143 = srem i32 %142, 4
%144 = icmp eq i32 %143, 0
%145 = zext i1 %144 to i32
%146 = add nuw nsw i32 %123, %145
%147 = add nuw nsw i64 %122, 1
%148 = icmp eq i64 %147, 16
br i1 %148, label %149, label %121
149: ; preds = %140
%150 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i32 %133, i32 %141)
%151 = call signext i8 (...) @getchar()
%152 = load i32, i32* @EXIT_SUCCESS
ret i32 %152
}