#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 */
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
char *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ assert(int *);
int /*<<< orphan*/ close(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int *malloc(int);
scalar_t__ mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int /*<<< orphan*/,
                int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
int sscanf(char *, char *, int *, int *);
int *make_r_from_ORlib(char *fname, int *m, int *n) {
  int fd;
  int size;
  char *filebuf;
  int fileidx, tmpfileidx;
  int *r;
  int filesize;
  int i;
  if ((fd = open(fname, O_RDONLY)) < 0) {
    perror("open()");
    return (NULL);
  }
  filesize = lseek(fd, 0, SEEK_END);
  if ((filebuf = (char *)mmap(0, filesize, PROT_READ, MAP_PRIVATE, fd,
                              (off_t)0)) == MAP_FAILED) {
    perror("mmap()");
    return (NULL);
  }
  close(fd);
  if (sscanf(filebuf, "%d%n", &size, &fileidx) != 1) {
    puts("failed to get problem size from file");
    return (NULL);
  }
  *m = *n = size;
  assert(r = malloc(sizeof(int) * size * size));
  i = 0;
  while (fileidx < filesize) {
    if (sscanf(filebuf + fileidx, "%d%n", r + i, &tmpfileidx) != 1)
      break;
    fileidx += tmpfileidx;
    i++;
  }
  return (r);
}


x86 assembly (clang, -O0):
<make_r_from_ORlib>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    11db <make_r_from_ORlib+0x4b>
lea    0xe37(%rip),%rdi
call   10b0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1320 <make_r_from_ORlib+0x190>
mov    -0x24(%rbp),%edi
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
mov    0x2dc4(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%edi
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    0x2da0(%rip),%rcx
cmp    (%rcx),%rax
jne    1242 <make_r_from_ORlib+0xb2>
lea    0xdd7(%rip),%rdi
call   10b0 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    1320 <make_r_from_ORlib+0x190>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x30(%rbp),%rdi
lea    0xdb9(%rip),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
je     1284 <make_r_from_ORlib+0xf4>
lea    0xda1(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    1320 <make_r_from_ORlib+0x190>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x28(%rbp),%rax
shl    $0x2,%rax
movslq -0x28(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rdi
mov    %rdi,-0x40(%rbp)
call   1070 <assert@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    1318 <make_r_from_ORlib+0x188>
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x40(%rbp),%rdx
movslq -0x48(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdx
lea    0xd24(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
je     1301 <make_r_from_ORlib+0x171>
jmp    1318 <make_r_from_ORlib+0x188>
mov    -0x38(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12bd <make_r_from_ORlib+0x12d>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_r_from_ORlib>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
test   %eax,%eax
js     12ae <make_r_from_ORlib+0x11e>
mov    %eax,%ebp
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,%r12d
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    0x2de7(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r12d,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%rbx
mov    0x2dc3(%rip),%rax
cmp    %rbx,(%rax)
je     12b7 <make_r_from_ORlib+0x127>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xdfa(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    12a0 <make_r_from_ORlib+0x110>
mov    0x14(%rsp),%edi
mov    %edi,(%r15)
mov    %edi,(%r14)
imul   %edi,%edi
shl    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <assert@plt>
mov    0xc(%rsp),%eax
cmp    %r12d,%eax
jge    12c6 <make_r_from_ORlib+0x136>
lea    0xdb3(%rip),%r15
lea    0x10(%rsp),%r13
mov    %r14,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %eax,%rdi
add    %rbx,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
mov    %r13,%rcx
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    12c6 <make_r_from_ORlib+0x136>
mov    0xc(%rsp),%eax
add    0x10(%rsp),%eax
mov    %eax,0xc(%rsp)
add    $0x4,%rbp
cmp    %r12d,%eax
jl     1270 <make_r_from_ORlib+0xe0>
jmp    12c6 <make_r_from_ORlib+0x136>
lea    0xd6c(%rip),%rdi
call   1030 <puts@plt>
jmp    12c3 <make_r_from_ORlib+0x133>
lea    0xd4b(%rip),%rdi
jmp    12be <make_r_from_ORlib+0x12e>
lea    0xd49(%rip),%rdi
call   10b0 <perror@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"open()\00"
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [7 x i8] c"mmap()\00"
@.str.2 = [5 x i8] c"%d%n\00"
@.str.3 = [37 x i8] c"failed to get problem size from file\00"
define i32* @make_r_from_ORlib(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%16 = load i8*, i8** %5
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %8
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32* null, i32** %4
br label %81
22: ; preds = %3
%23 = load i32, i32* %8
%24 = load i32, i32* @SEEK_END
%25 = call i32 @lseek(i32 %23, i32 0, i32 %24)
store i32 %25, i32* %14
%26 = load i32, i32* %14
%27 = load i32, i32* @PROT_READ
%28 = load i32, i32* @MAP_PRIVATE
%29 = load i32, i32* %8
%30 = call i64 @mmap(i32 0, i32 %26, i32 %27, i32 %28, i32 %29, i32 0)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %10
%32 = load i8*, i8** @MAP_FAILED
%33 = icmp eq i8* %31, %32
br i1 %33, label %34, label %36
34: ; preds = %22
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32* null, i32** %4
br label %81
36: ; preds = %22
%37 = load i32, i32* %8
%38 = call i32 @close(i32 %37)
%39 = load i8*, i8** %10
%40 = call i32 @sscanf(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %9, i32* %11)
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @puts(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
store i32* null, i32** %4
br label %81
44: ; preds = %36
%45 = load i32, i32* %9
%46 = load i32*, i32** %7
store i32 %45, i32* %46
%47 = load i32*, i32** %6
store i32 %45, i32* %47
%48 = load i32, i32* %9
%49 = sext i32 %48 to i64
%50 = mul i64 4, %49
%51 = load i32, i32* %9
%52 = sext i32 %51 to i64
%53 = mul i64 %50, %52
%54 = trunc i64 %53 to i32
%55 = call i32* @malloc(i32 %54)
store i32* %55, i32** %13
%56 = call i32 @assert(i32* %55)
store i32 0, i32* %15
br label %57
57: ; preds = %73, %44
%58 = load i32, i32* %11
%59 = load i32, i32* %14
%60 = icmp slt i32 %58, %59
br i1 %60, label %61, label %79
61: ; preds = %57
%62 = load i8*, i8** %10
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i32*, i32** %13
%67 = load i32, i32* %15
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
%70 = call i32 @sscanf(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %69, i32* %12)
%71 = icmp ne i32 %70, 1
br i1 %71, label %72, label %73
72: ; preds = %61
br label %79
73: ; preds = %61
%74 = load i32, i32* %12
%75 = load i32, i32* %11
%76 = add nsw i32 %75, %74
store i32 %76, i32* %11
%77 = load i32, i32* %15
%78 = add nsw i32 %77, 1
store i32 %78, i32* %15
br label %57
79: ; preds = %72, %57
%80 = load i32*, i32** %13
store i32* %80, i32** %4
br label %81
81: ; preds = %79, %42, %34, %20
%82 = load i32*, i32** %4
ret i32* %82
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [7 x i8] c"open()\00"
@SEEK_END = global i32 0
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.1 = [7 x i8] c"mmap()\00"
@.str.2 = [5 x i8] c"%d%n\00"
@.str.3 = [37 x i8] c"failed to get problem size from file\00"
define i32* @make_r_from_ORlib(i8* nocapture %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %0, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %54
15: ; preds = %3
%16 = load i32, i32* @SEEK_END
%17 = tail call i32 @lseek(i32 %11, i32 0, i32 %16)
%18 = load i32, i32* @PROT_READ
%19 = load i32, i32* @MAP_PRIVATE
%20 = tail call i64 @mmap(i32 0, i32 %17, i32 %18, i32 %19, i32 %11, i32 0)
%21 = inttoptr i64 %20 to i8*
%22 = load i8*, i8** @MAP_FAILED
%23 = icmp eq i8* %22, %21
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %54
26: ; preds = %15
%27 = tail call i32 @close(i32 %11)
%28 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5)
%29 = icmp eq i32 %28, 1
br i1 %29, label %32, label %30
30: ; preds = %26
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %54
32: ; preds = %26
%33 = load i32, i32* %4
store i32 %33, i32* %2
store i32 %33, i32* %1
%34 = shl i32 %33, 2
%35 = mul i32 %34, %33
%36 = call i32* @malloc(i32 %35)
%37 = call i32 @assert(i32* %36)
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, %17
br i1 %39, label %40, label %54
40: ; preds = %32, %48
%41 = phi i64 [ %52, %48 ], [ 0, %32 ]
%42 = phi i32 [ %51, %48 ], [ %38, %32 ]
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %21, i64 %43
%45 = getelementptr inbounds i32, i32* %36, i64 %41
%46 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %45, i32* %6)
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %54
48: ; preds = %40
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = add nsw i32 %50, %49
store i32 %51, i32* %5
%52 = add nuw i64 %41, 1
%53 = icmp slt i32 %51, %17
br i1 %53, label %40, label %54
54: ; preds = %40, %48, %32, %30, %24, %13
%55 = phi i32* [ null, %13 ], [ null, %24 ], [ null, %30 ], [ %36, %32 ], [ %36, %48 ], [ %36, %40 ]
ret i32* %55
}