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

/* Variables and functions */
scalar_t__ do_command(char *, int /*<<< orphan*/);
char *expand_tilde(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ isspace(char);
int last_error();
int /*<<< orphan*/ printc(char *, char *);
int /*<<< orphan*/ printc_err(char *, char const *, int);
int process_file(const char *filename, int show) {
  FILE *in;
  char buf[1024], *path;
  int line_no = 0;
  path = expand_tilde(filename);
  if (!path)
    return -1;
  in = fopen(path, "r");
  free(path);
  if (!in) {
    printc_err("read: can't open %s: %s\n", filename, last_error());
    return -1;
  }
  while (fgets(buf, sizeof(buf), in)) {
    char *cmd = buf;
    line_no++;
    while (*cmd && isspace(*cmd))
      cmd++;
    if (*cmd == '#')
      continue;
    if (show)
      printc("\x1b[1m=>\x1b[0m %s", cmd);
    if (do_command(cmd, 0) < 0) {
      printc_err("read: error processing %s (line %d)\n", filename, line_no);
      fclose(in);
      return -1;
    }
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <expand_tilde@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11e6 <process_file+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1376 <process_file+0x1d6>
mov    -0x428(%rbp),%rdi
lea    0xe0c(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x428(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1247 <process_file+0xa7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    $0x0,%al
call   10a0 <last_error@plt>
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
lea    0xdcc(%rip),%rdi
call   1060 <printc_err@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1376 <process_file+0x1d6>
jmp    124c <process_file+0xac>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1366 <process_file+0x1c6>
lea    -0x420(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
mov    -0x438(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x441(%rbp)
je     12bf <process_file+0x11f>
mov    -0x438(%rbp),%rax
movsbl (%rax),%edi
call   1080 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x441(%rbp)
mov    -0x441(%rbp),%al
test   $0x1,%al
jne    12d2 <process_file+0x132>
jmp    12e9 <process_file+0x149>
mov    -0x438(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x438(%rbp)
jmp    1288 <process_file+0xe8>
mov    -0x438(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    1301 <process_file+0x161>
jmp    124c <process_file+0xac>
cmpl   $0x0,-0x14(%rbp)
je     131e <process_file+0x17e>
mov    -0x438(%rbp),%rsi
lea    0xd02(%rip),%rdi
call   10b0 <printc@plt>
mov    -0x438(%rbp),%rdi
xor    %esi,%esi
call   1040 <do_command@plt>
cmp    $0x0,%rax
jge    1361 <process_file+0x1c1>
mov    -0x10(%rbp),%rsi
mov    -0x42c(%rbp),%edx
lea    0xce2(%rip),%rdi
call   1060 <printc_err@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1376 <process_file+0x1d6>
jmp    124c <process_file+0xac>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%r12d
mov    %rdi,%r15
call   1070 <expand_tilde@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     12dd <process_file+0x13d>
mov    %rax,%rbx
lea    0xe2c(%rip),%rsi
mov    %rax,%rdi
call   10c0 <fopen@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r13,%r13
je     12a5 <process_file+0x105>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1299 <process_file+0xf9>
xor    %ebx,%ebx
jmp    1238 <process_file+0x98>
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <do_command@plt>
test   %rax,%rax
js     12bf <process_file+0x11f>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1299 <process_file+0xf9>
add    $0x1,%ebx
mov    (%rsp),%al
mov    %r14,%rbp
test   %al,%al
je     1280 <process_file+0xe0>
mov    %r14,%rbp
nopl   0x0(%rax,%rax,1)
movsbl %al,%edi
call   1080 <isspace@plt>
test   %rax,%rax
je     1270 <process_file+0xd0>
movzbl 0x1(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1250 <process_file+0xb0>
jmp    1280 <process_file+0xe0>
nopl   0x0(%rax,%rax,1)
cmpb   $0x23,0x0(%rbp)
je     1223 <process_file+0x83>
cs nopw 0x0(%rax,%rax,1)
test   %r12d,%r12d
je     1210 <process_file+0x70>
lea    0xd8f(%rip),%rdi
mov    %rbp,%rsi
call   10b0 <printc@plt>
jmp    1210 <process_file+0x70>
mov    %r13,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
jmp    12dd <process_file+0x13d>
xor    %eax,%eax
call   10a0 <last_error@plt>
lea    0xd4f(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1060 <printc_err@plt>
jmp    12dd <process_file+0x13d>
lea    0xd63(%rip),%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1060 <printc_err@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"read: can't open %s: %s\0A\00"
@.str.2 = [14 x i8] c"\1B[1m=>\1B[0m %s\00"
@.str.3 = [37 x i8] c"read: error processing %s (line %d)\0A\00"
define i32 @process_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %9
%11 = load i8*, i8** %4
%12 = call i8* @expand_tilde(i8* %11)
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 -1, i32* %3
br label %78
16: ; preds = %2
%17 = load i8*, i8** %8
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i8*, i8** %8
%20 = call i32 @free(i8* %19)
%21 = load i32*, i32** %6
%22 = icmp ne i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = call i32 (...) @last_error()
%26 = call i32 @printc_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 %25)
store i32 -1, i32* %3
br label %78
27: ; preds = %16
br label %28
28: ; preds = %74, %57, %27
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%30 = load i32*, i32** %6
%31 = call i64 @fgets(i8* %29, i32 1024, i32* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %75
33: ; preds = %28
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
store i8* %34, i8** %10
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %37
37: ; preds = %49, %33
%38 = load i8*, i8** %10
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37
%43 = load i8*, i8** %10
%44 = load i8, i8* %43
%45 = call i64 @isspace(i8 signext %44)
%46 = icmp ne i64 %45, 0
br label %47
47: ; preds = %42, %37
%48 = phi i1 [ false, %37 ], [ %46, %42 ]
br i1 %48, label %49, label %52
49: ; preds = %47
%50 = load i8*, i8** %10
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %10
br label %37
52: ; preds = %47
%53 = load i8*, i8** %10
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 35
br i1 %56, label %57, label %58
57: ; preds = %52
br label %28
58: ; preds = %52
%59 = load i32, i32* %5
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = load i8*, i8** %10
%63 = call i32 @printc(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %58
%65 = load i8*, i8** %10
%66 = call i64 @do_command(i8* %65, i32 0)
%67 = icmp slt i64 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %64
%69 = load i8*, i8** %4
%70 = load i32, i32* %9
%71 = call i32 @printc_err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %69, i32 %70)
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
store i32 -1, i32* %3
br label %78
74: ; preds = %64
br label %28
75: ; preds = %28
%76 = load i32*, i32** %6
%77 = call i32 @fclose(i32* %76)
store i32 0, i32* %3
br label %78
78: ; preds = %75, %68, %23, %15
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"read: can't open %s: %s\0A\00"
@.str.2 = [14 x i8] c"\1B[1m=>\1B[0m %s\00"
@.str.3 = [37 x i8] c"read: error processing %s (line %d)\0A\00"
define i32 @process_file(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @expand_tilde(i8* %0)
%6 = icmp eq i8* %5, null
br i1 %6, label %51, label %7
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @free(i8* %5)
%10 = icmp eq i32* %8, null
br i1 %10, label %16, label %11
11: ; preds = %7
%12 = call i64 @fgets(i8* %4, i32 1024, i32* %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %49, label %14
14: ; preds = %11
%15 = icmp eq i32 %1, 0
br label %19
16: ; preds = %7
%17 = tail call i32 (...) @last_error()
%18 = tail call i32 @printc_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %17)
br label %51
19: ; preds = %14, %46
%20 = phi i32 [ 0, %14 ], [ %21, %46 ]
%21 = add nuw nsw i32 %20, 1
%22 = load i8, i8* %4
%23 = icmp eq i8 %22, 0
br i1 %23, label %36, label %24
24: ; preds = %19, %29
%25 = phi i8 [ %31, %29 ], [ %22, %19 ]
%26 = phi i8* [ %30, %29 ], [ %4, %19 ]
%27 = call i64 @isspace(i8 signext %25)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %26, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %36, label %24
33: ; preds = %24
%34 = load i8, i8* %26
%35 = icmp eq i8 %34, 35
br i1 %35, label %46, label %36
36: ; preds = %29, %19, %33
%37 = phi i8* [ %26, %33 ], [ %4, %19 ], [ %30, %29 ]
br i1 %15, label %40, label %38
38: ; preds = %36
%39 = call i32 @printc(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %37)
br label %40
40: ; preds = %38, %36
%41 = call i64 @do_command(i8* %37, i32 0)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @printc_err(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %21)
%45 = call i32 @fclose(i32* %8)
br label %51
46: ; preds = %40, %33
%47 = call i64 @fgets(i8* %4, i32 1024, i32* %8)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %19
49: ; preds = %46, %11
%50 = call i32 @fclose(i32* %8)
br label %51
51: ; preds = %43, %2, %49, %16
%52 = phi i32 [ 0, %49 ], [ -1, %16 ], [ -1, %2 ], [ -1, %43 ]
ret i32 %52
}