#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strtok(char *, char *);
int read_matrix(char mname[100]) {
  FILE *fmat;
  char buf[100], *tmpstring;
  if (NULL == (fmat = fopen("./matfileReal", "r"))) {
    fprintf(stderr, "cannot open file: matfile\n");
    exit(1);
  }
  if (fgets(buf, 100, fmat) == NULL) {
    fprintf(stderr, "Error reading matrix list");
    exit(1);
  }
  tmpstring = (char *)strtok(buf, " ");
  tmpstring++;
  tmpstring[strlen(tmpstring) - 1] = '\0';
  strcpy(mname, --tmpstring);
  fclose(fmat);
  return 0;
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe6a(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d3 <read_matrix+0x53>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    120e <read_matrix+0x8e>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    -0x80(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x88(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x88(%rbp),%rsi
add    $0xffffffffffffffff,%rsi
mov    %rsi,-0x88(%rbp)
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %r15
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %rdi,%r14
lea    0xe6d(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fc <read_matrix+0x7c>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120e <read_matrix+0x8e>
lea    0xe82(%rip),%rsi
mov    %rsp,%rdi
call   1090 <strtok@plt>
mov    %rax,%rbx
lea    0x1(%rax),%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,(%rax,%rbx,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
jmp    121e <read_matrix+0x9e>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
lea    0xe0d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"./matfileReal\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"cannot open file: matfile\0A\00"
@.str.3 = [26 x i8] c"Error reading matrix list\00"
@.str.4 = [2 x i8] c" \00"
define i32 @read_matrix(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = icmp eq i32* null, %6
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32* @fgets(i8* %13, i32 100, i32* %14)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %12
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%23 = call i64 @strtok(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %2
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %5
%36 = call i32 @strcpy(i8* %33, i8* %35)
%37 = load i32*, i32** %3
%38 = call i32 @fclose(i32* %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"./matfileReal\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"cannot open file: matfile\0A\00"
@.str.3 = [26 x i8] c"Error reading matrix list\00"
@.str.4 = [2 x i8] c" \00"
define i32 @read_matrix(i8* %0) {
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = call i32* @fgets(i8* %3, i32 100, i32* %4)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
%18 = call i64 @strtok(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%19 = inttoptr i64 %18 to i8*
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
store i8 0, i8* %24
%25 = call i32 @strcpy(i8* %0, i8* %19)
%26 = call i32 @fclose(i32* %4)
ret i32 0
}