#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 INT_MAX;
size_t midx(unsigned int, unsigned int, unsigned int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
void print_smat(int *arr, unsigned int n) {
  unsigned int i, j;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      int val = arr[midx(i, j, n)];
      if (val != (INT_MAX))
        printf("%d ", arr[midx(i, j, n)]);
      else
        printf("~ ");
    }
    puts("");
  }
}


x86 assembly (clang, -O0):
<print_smat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     1208 <print_smat+0xd8>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11ee <print_smat+0xbe>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <midx@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e56(%rip),%rcx
cmp    (%rcx),%eax
je     11cd <print_smat+0x9d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <midx@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    (%rax,%rcx,4),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11db <print_smat+0xab>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e0 <print_smat+0xb0>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <print_smat+0x29>
lea    0xe0e(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <print_smat+0x16>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_smat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     11c6 <print_smat+0x96>
mov    %esi,%ebx
mov    %rdi,%r14
mov    $0x1,%r13d
mov    0x2e93(%rip),%r15
lea    0xea4(%rip),%r12
jmp    1173 <print_smat+0x43>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x1,%r13d
cmp    %ebx,%r13d
ja     11c6 <print_smat+0x96>
mov    $0x1,%ebp
jmp    1195 <print_smat+0x65>
nopw   0x0(%rax,%rax,1)
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebx,%ebp
ja     1160 <print_smat+0x30>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <midx@plt>
mov    (%r14,%rax,4),%eax
cmp    (%r15),%eax
je     1180 <print_smat+0x50>
mov    %r13d,%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1040 <midx@plt>
mov    (%r14,%rax,4),%esi
mov    %r12,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    118e <print_smat+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@INT_MAX = global i32 0
@.str = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"~ \00"
@.str.2 = [1 x i8] zeroinitializer
define void @print_smat(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 1, i32* %5
br label %8
8: ; preds = %45, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp ule i32 %9, %10
br i1 %11, label %12, label %48
12: ; preds = %8
store i32 1, i32* %6
br label %13
13: ; preds = %40, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp ule i32 %14, %15
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i32*, i32** %3
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = load i32, i32* %4
%22 = call i64 @midx(i32 %19, i32 %20, i32 %21)
%23 = getelementptr inbounds i32, i32* %18, i64 %22
%24 = load i32, i32* %23
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = load i32, i32* @INT_MAX
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %37
28: ; preds = %17
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = load i32, i32* %4
%33 = call i64 @midx(i32 %30, i32 %31, i32 %32)
%34 = getelementptr inbounds i32, i32* %29, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %35)
br label %39
37: ; preds = %17
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %28
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add i32 %41, 1
store i32 %42, i32* %6
br label %13
43: ; preds = %13
%44 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %45
45: ; preds = %43
%46 = load i32, i32* %5
%47 = add i32 %46, 1
store i32 %47, i32* %5
br label %8
48: ; preds = %8
ret void
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str = [4 x i8] c"%d \00"
@.str.1 = [3 x i8] c"~ \00"
define void @print_smat(i32* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %27, label %4
4: ; preds = %2, %23
%5 = phi i32 [ %25, %23 ], [ 1, %2 ]
br label %6
6: ; preds = %4, %20
%7 = phi i32 [ %21, %20 ], [ 1, %4 ]
%8 = tail call i64 @midx(i32 %5, i32 %7, i32 %1)
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = load i32, i32* @INT_MAX
%12 = icmp eq i32 %10, %11
br i1 %12, label %18, label %13
13: ; preds = %6
%14 = tail call i64 @midx(i32 %5, i32 %7, i32 %1)
%15 = getelementptr inbounds i32, i32* %0, i64 %14
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %6
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = add i32 %7, 1
%22 = icmp ugt i32 %21, %1
br i1 %22, label %23, label %6
23: ; preds = %20
%24 = tail call i32 @putchar(i32 10)
%25 = add i32 %5, 1
%26 = icmp ugt i32 %25, %1
br i1 %26, label %27, label %4
27: ; preds = %23, %2
ret void
}