#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 /*<<< orphan*/ abort();
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, size_t);
int /*<<< orphan*/ upper_triangle(unsigned char *, size_t);
int singular(unsigned char *mtx, size_t len) {
  unsigned char *copy = malloc(len * len);
  if (!copy)
    abort();
  memcpy(copy, mtx, len * len);
  upper_triangle(copy, len);
  int ret = 0;
  for (int i = 0; i < len * len; i += len + 1) {
    if (!copy[i]) {
      ret = 1;
      break;
    }
  }
  free(copy);
  return ret;
}


x86 assembly (clang, -O0):
<singular>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
imul   -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <singular+0x34>
mov    $0x0,%al
call   1040 <abort@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
imul   -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <upper_triangle@plt>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   -0x10(%rbp),%rcx
cmp    %rcx,%rax
jae    1205 <singular+0xb5>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11e9 <singular+0x99>
movl   $0x1,-0x1c(%rbp)
jmp    1205 <singular+0xb5>
jmp    11ee <singular+0x9e>
mov    -0x10(%rbp),%rcx
add    $0x1,%rcx
movslq -0x20(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x20(%rbp)
jmp    11b5 <singular+0x65>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<singular>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rbx
imul   %rsi,%rbx
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d0 <singular+0x80>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <upper_triangle@plt>
test   %rbx,%rbx
je     11b1 <singular+0x61>
add    $0x1,%r15
xor    %eax,%eax
nopl   0x0(%rax)
cmpb   $0x0,(%r14,%rax,1)
je     11b5 <singular+0x65>
add    %r15d,%eax
cltq
cmp    %rbx,%rax
jb     11a0 <singular+0x50>
xor    %ebx,%ebx
jmp    11ba <singular+0x6a>
mov    $0x1,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
define i32 @singular(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = load i64, i64* %4
%10 = mul i64 %8, %9
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = load i8*, i8** %3
%19 = load i64, i64* %4
%20 = load i64, i64* %4
%21 = mul i64 %19, %20
%22 = call i32 @memcpy(i8* %17, i8* %18, i64 %21)
%23 = load i8*, i8** %5
%24 = load i64, i64* %4
%25 = call i32 @upper_triangle(i8* %23, i64 %24)
store i32 0, i32* %6
store i32 0, i32* %7
br label %26
26: ; preds = %42, %16
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = load i64, i64* %4
%30 = load i64, i64* %4
%31 = mul i64 %29, %30
%32 = icmp ult i64 %28, %31
br i1 %32, label %33, label %49
33: ; preds = %26
%34 = load i8*, i8** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %33
store i32 1, i32* %6
br label %49
41: ; preds = %33
br label %42
42: ; preds = %41
%43 = load i64, i64* %4
%44 = add i64 %43, 1
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = add i64 %46, %44
%48 = trunc i64 %47 to i32
store i32 %48, i32* %7
br label %26
49: ; preds = %40, %26
%50 = load i8*, i8** %5
%51 = call i32 @free(i8* %50)
%52 = load i32, i32* %6
ret i32 %52
}

LLVM IR (-O2):
define i32 @singular(i8* %0, i64 %1) {
%3 = mul i64 %1, %1
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 (...) @abort()
unreachable
8: ; preds = %2
%9 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %3)
%10 = tail call i32 @upper_triangle(i8* %4, i64 %1)
%11 = icmp eq i64 %3, 0
br i1 %11, label %24, label %12
12: ; preds = %8
%13 = add i64 %1, 1
br label %14
14: ; preds = %12, %19
%15 = phi i64 [ 0, %12 ], [ %22, %19 ]
%16 = getelementptr inbounds i8, i8* %4, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = add i64 %13, %15
%21 = shl i64 %20, 32
%22 = ashr exact i64 %21, 32
%23 = icmp ult i64 %22, %3
br i1 %23, label %14, label %24
24: ; preds = %19, %14, %8
%25 = phi i32 [ 0, %8 ], [ 1, %14 ], [ 0, %19 ]
%26 = tail call i32 @free(i8* %4)
ret i32 %25
}