int doexrc(filename)
char *filename;
{
  int fd;
  int len;
  char *cmd;
  char *end;
  char buf[1000];
  fd = open(filename, 0);
  if (fd < 0) {
    return 0;
  }
  len = read(fd, buf, 1000);
  close(fd);
  for (cmd = buf; cmd < &buf[len]; cmd = end + 1) {
    for (end = cmd; *end != '\n'; end++) {
    }
    *end = '\0';
    doexcmd(cmd);
  }
  return 1;
}


x86 assembly (clang, -O0):
<doexrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1175 <doexrc+0x35>
movl   $0x0,-0x4(%rbp)
jmp    1216 <doexrc+0xd6>
mov    -0x14(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3e8,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1030 <close@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rdx
lea    -0x410(%rbp),%rcx
add    %rdx,%rcx
cmp    %rcx,%rax
jae    120f <doexrc+0xcf>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11ec <doexrc+0xac>
jmp    11db <doexrc+0x9b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c6 <doexrc+0x86>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1050 <doexcmd@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11a3 <doexrc+0x63>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doexrc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
xor    %r14d,%r14d
xor    %esi,%esi
xor    %eax,%eax
call   1060 <open@plt>
test   %eax,%eax
js     11bf <doexrc+0x7f>
mov    %eax,%ebx
mov    %rsp,%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1040 <read@plt>
mov    %eax,%r15d
mov    %ebx,%edi
xor    %eax,%eax
call   1030 <close@plt>
mov    $0x1,%r14d
test   %r15d,%r15d
jle    11bf <doexrc+0x7f>
movslq %r15d,%rax
lea    (%rsp,%rax,1),%r15
mov    %rbp,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0xa,(%rbx)
lea    0x1(%rbx),%rbx
jne    11a0 <doexrc+0x60>
movb   $0x0,-0x1(%rbx)
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <doexcmd@plt>
mov    %rbx,%rbp
cmp    %r15,%rbx
jb     11a0 <doexrc+0x60>
mov    %r14d,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @doexrc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1000 x i8]
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %9, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 0, i32* %2
br label %46
14: ; preds = %1
%15 = load i32, i32* %4
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%17 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %15, i8* %16, i32 1000)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
store i8* %20, i8** %6
br label %21
21: ; preds = %42, %14
%22 = load i8*, i8** %6
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %24
%26 = icmp ult i8* %22, %25
br i1 %26, label %27, label %45
27: ; preds = %21
%28 = load i8*, i8** %6
store i8* %28, i8** %7
br label %29
29: ; preds = %35, %27
%30 = load i8*, i8** %7
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 10
br i1 %33, label %34, label %38
34: ; preds = %29
br label %35
35: ; preds = %34
%36 = load i8*, i8** %7
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %7
br label %29
38: ; preds = %29
%39 = load i8*, i8** %7
store i8 0, i8* %39
%40 = load i8*, i8** %6
%41 = call i32 (i8*, ...) bitcast (i32 (...)* @doexcmd to i32 (i8*, ...)*)(i8* %40)
br label %42
42: ; preds = %38
%43 = load i8*, i8** %7
%44 = getelementptr inbounds i8, i8* %43, i64 1
store i8* %44, i8** %6
br label %21
45: ; preds = %21
store i32 1, i32* %2
br label %46
46: ; preds = %45, %13
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @doexrc(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (i8*, i32, ...) bitcast (i32 (...)* @open to i32 (i8*, i32, ...)*)(i8* %0, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %22, label %6
6: ; preds = %1
%7 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %4, i8* %3, i32 1000)
%8 = call i32 (i32, ...) bitcast (i32 (...)* @close to i32 (i32, ...)*)(i32 %4)
%9 = sext i32 %7 to i64
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %9
%11 = icmp sgt i32 %7, 0
br i1 %11, label %12, label %22
12: ; preds = %6, %19
%13 = phi i8* [ %18, %19 ], [ %3, %6 ]
br label %14
14: ; preds = %14, %12
%15 = phi i8* [ %18, %14 ], [ %13, %12 ]
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 10
%18 = getelementptr inbounds i8, i8* %15, i64 1
br i1 %17, label %19, label %14
19: ; preds = %14
store i8 0, i8* %15
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @doexcmd to i32 (i8*, ...)*)(i8* %13)
%21 = icmp ult i8* %18, %10
br i1 %21, label %12, label %22
22: ; preds = %19, %6, %1
%23 = phi i32 [ 0, %1 ], [ 1, %6 ], [ 1, %19 ]
ret i32 %23
}