#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*/ cli_docmd(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *strchr(char *, char);
int cli_load_file(char *filename) {
  char buf[255];
  FILE *file;
  file = fopen(filename, "r");
  if (!file) {
    return -1;
  }
  while (fgets(buf, 255, file)) {
    char *c = strchr(buf, '\n');
    char *t;
    t = buf;
    if (c)
      *c = '\0';
    if (*buf) {
      while (*t == ' ' || *t == '\t')
        t++;
      cli_docmd(buf, NULL);
    }
  }
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<cli_load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    1190 <cli_load_file+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    128a <cli_load_file+0x13a>
jmp    1195 <cli_load_file+0x45>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1277 <cli_load_file+0x127>
lea    -0x110(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x120(%rbp)
je     11f5 <cli_load_file+0xa5>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
cmpb   $0x0,-0x110(%rbp)
je     1272 <cli_load_file+0x122>
jmp    1207 <cli_load_file+0xb7>
mov    -0x128(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x129(%rbp)
je     1238 <cli_load_file+0xe8>
mov    -0x128(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x9,%eax
sete   %al
mov    %al,-0x129(%rbp)
mov    -0x129(%rbp),%al
test   $0x1,%al
jne    124b <cli_load_file+0xfb>
jmp    1262 <cli_load_file+0x112>
mov    -0x128(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x128(%rbp)
jmp    1207 <cli_load_file+0xb7>
lea    -0x110(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <cli_docmd@plt>
jmp    1195 <cli_load_file+0x45>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_load_file>:
push   %r14
push   %rbx
sub    $0x108,%rsp
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d8 <cli_load_file+0x88>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11cc <cli_load_file+0x7c>
mov    %rsp,%rbx
jmp    11a5 <cli_load_file+0x55>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11cc <cli_load_file+0x7c>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ba <cli_load_file+0x6a>
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
je     1190 <cli_load_file+0x40>
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <cli_docmd@plt>
jmp    1190 <cli_load_file+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11dd <cli_load_file+0x8d>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @cli_load_file(i8* nocapture %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %23, label %6
6: ; preds = %1
%7 = call i64 @fgets(i8* %3, i32 255, i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %6, %18
%10 = call i8* @strchr(i8* %3, i8 signext 10)
%11 = icmp eq i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9
store i8 0, i8* %10
br label %13
13: ; preds = %12, %9
%14 = load i8, i8* %3
%15 = icmp eq i8 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = call i32 @cli_docmd(i8* %3, i32* null)
br label %18
18: ; preds = %16, %13
%19 = call i64 @fgets(i8* %3, i32 255, i32* %4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %18, %6
%22 = call i32 @fclose(i32* %4)
br label %23
23: ; preds = %1, %21
%24 = phi i32 [ 0, %21 ], [ -1, %1 ]
ret i32 %24
}