#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 */
char EOF;
int /*<<< orphan*/ correct_path(char **);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ file_exists(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int save_paths(char **paths, char *filename) {
  FILE *Fp;
  int i, j;
  char c;
  if (!file_exists(filename))
    return -1;
  Fp = fopen(filename, "r");
  if (Fp == NULL)
    return -2;
  i = 0;
  j = 0;
  while ((c = fgetc(Fp)) != EOF) {
    if (c == '\r')
      continue;
    if (c != '\n') {
      paths[i][j] = c;
      j++;
    } else {
      correct_path(&paths[i]);
      i++;
      j = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<save_paths>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%eax
jne    116e <save_paths+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <save_paths+0xfb>
mov    -0x18(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1199 <save_paths+0x59>
movl   $0xfffffffe,-0x4(%rbp)
jmp    123b <save_paths+0xfb>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl %al,%eax
mov    0x2e2b(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1234 <save_paths+0xf4>
movsbl -0x29(%rbp),%eax
cmp    $0xd,%eax
jne    11da <save_paths+0x9a>
jmp    11a7 <save_paths+0x67>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
je     120b <save_paths+0xcb>
mov    -0x29(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    122f <save_paths+0xef>
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
call   1050 <correct_path@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    11a7 <save_paths+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_paths>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <file_exists@plt>
test   %eax,%eax
je     11c4 <save_paths+0x84>
lea    0xe9f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11cb <save_paths+0x8b>
mov    %rax,%rbx
xor    %eax,%eax
mov    0x2e6e(%rip),%r15
mov    %eax,%r12d
xor    %ebp,%ebp
nop
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
je     11c0 <save_paths+0x80>
cmp    $0xd,%al
je     1180 <save_paths+0x40>
cmp    $0xa,%al
je     11b0 <save_paths+0x70>
mov    (%r14,%r12,8),%rcx
mov    %ebp,%edx
mov    %al,(%rcx,%rdx,1)
add    $0x1,%ebp
jmp    1180 <save_paths+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r14,%r12,8),%rdi
call   1050 <correct_path@plt>
lea    0x1(%r12),%eax
jmp    117a <save_paths+0x3a>
xor    %eax,%eax
jmp    11d0 <save_paths+0x90>
mov    $0xffffffff,%eax
jmp    11d0 <save_paths+0x90>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @save_paths(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8** %0, i8*** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @file_exists(i8* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %2
store i32 -1, i32* %3
br label %59
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
store i32 -2, i32* %3
br label %59
20: ; preds = %14
store i32 0, i32* %7
store i32 0, i32* %8
br label %21
21: ; preds = %57, %32, %20
%22 = load i32*, i32** %6
%23 = call signext i8 @fgetc(i32* %22)
store i8 %23, i8* %9
%24 = sext i8 %23 to i32
%25 = load i8, i8* @EOF
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br i1 %27, label %28, label %58
28: ; preds = %21
%29 = load i8, i8* %9
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 13
br i1 %31, label %32, label %33
32: ; preds = %28
br label %21
33: ; preds = %28
%34 = load i8, i8* %9
%35 = sext i8 %34 to i32
%36 = icmp ne i32 %35, 10
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i8, i8* %9
%39 = load i8**, i8*** %4
%40 = load i32, i32* %7
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 %38, i8* %46
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %57
49: ; preds = %33
%50 = load i8**, i8*** %4
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = call i32 @correct_path(i8** %53)
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
store i32 0, i32* %8
br label %57
57: ; preds = %49, %37
br label %21
58: ; preds = %21
store i32 0, i32* %3
br label %59
59: ; preds = %58, %19, %13
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @save_paths(i8** %0, i8* %1) {
%3 = tail call i32 @file_exists(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %29, label %8
8: ; preds = %5, %24
%9 = phi i32 [ %28, %24 ], [ 0, %5 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
br label %12
12: ; preds = %8, %19
%13 = phi i32 [ %23, %19 ], [ 0, %8 ]
br label %14
14: ; preds = %12, %18
%15 = tail call signext i8 @fgetc(i32* %6)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %29, label %18
18: ; preds = %14
switch i8 %15, label %19 [
i8 13, label %14
i8 10, label %24
]
19: ; preds = %18
%20 = load i8*, i8** %11
%21 = zext i32 %13 to i64
%22 = getelementptr inbounds i8, i8* %20, i64 %21
store i8 %15, i8* %22
%23 = add nuw nsw i32 %13, 1
br label %12
24: ; preds = %18
%25 = zext i32 %9 to i64
%26 = getelementptr inbounds i8*, i8** %0, i64 %25
%27 = tail call i32 @correct_path(i8** %26)
%28 = add nuw nsw i32 %9, 1
br label %8
29: ; preds = %14, %5, %2
%30 = phi i32 [ -1, %2 ], [ -2, %5 ], [ 0, %14 ]
ret i32 %30
}