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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ memchr(char *, char, int);
int /*<<< orphan*/ memmove(char *, char *, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ parse_cmd_line(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
void load_commands(char *cmd_file) {
  char buff[2048];
  char *p, *s, *e, *ee;
  int fd;
  int n, rest, numline;
  fd = open(cmd_file, O_RDONLY);
  if (fd == -1) {
    printf("Cannot open alcatest.cmd, terminating...\n");
    exit(1);
  }
  numline = 0;
  rest = 2048;
  p = buff;
  while ((n = read(fd, p, rest)) > 0) {
    s = buff;
    ee = p + n;
    while ((e = (char *)memchr(s, '\n', ee - s))) {
      *e = '\0';
      numline++;
      if (!parse_cmd_line(s)) {
        printf("ERROR: syntax error at line %d in %s\n", numline, cmd_file);
        exit(2);
      }
      s = e + 1;
    }
    if (s == buff) {
      printf("ERROR: a line exceed %d characters in %s.\n", 2048, cmd_file);
      close(fd);
      exit(2);
    }
    memmove(buff, s, ee - s);
    rest = 2048 - (ee - s);
    p = buff + (ee - s);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<load_commands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x834(%rbp)
cmpl   $0xffffffff,-0x834(%rbp)
jne    11cc <load_commands+0x4c>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x840(%rbp)
movl   $0x800,-0x83c(%rbp)
lea    -0x810(%rbp),%rax
mov    %rax,-0x818(%rbp)
mov    -0x834(%rbp),%edi
mov    -0x818(%rbp),%rsi
mov    -0x83c(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x838(%rbp)
cmp    $0x0,%eax
jle    1386 <load_commands+0x206>
lea    -0x810(%rbp),%rax
mov    %rax,-0x820(%rbp)
mov    -0x818(%rbp),%rax
movslq -0x838(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x830(%rbp)
mov    -0x820(%rbp),%rdi
mov    -0x830(%rbp),%rax
mov    -0x820(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0xa,%esi
call   1060 <memchr@plt>
mov    %rax,-0x828(%rbp)
cmp    $0x0,%rax
je     12d7 <load_commands+0x157>
mov    -0x828(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x840(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x840(%rbp)
mov    -0x820(%rbp),%rdi
call   1030 <parse_cmd_line@plt>
cmp    $0x0,%eax
jne    12c0 <load_commands+0x140>
mov    -0x840(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x820(%rbp)
jmp    123b <load_commands+0xbb>
mov    -0x820(%rbp),%rax
lea    -0x810(%rbp),%rcx
cmp    %rcx,%rax
jne    131a <load_commands+0x19a>
mov    -0x8(%rbp),%rdx
lea    0xd57(%rip),%rdi
mov    $0x800,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x834(%rbp),%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    -0x810(%rbp),%rdi
mov    -0x820(%rbp),%rsi
mov    -0x830(%rbp),%rax
mov    -0x820(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1080 <memmove@plt>
mov    -0x830(%rbp),%rcx
mov    -0x820(%rbp),%rax
sub    %rax,%rcx
mov    $0x800,%eax
sub    %rcx,%rax
mov    %eax,-0x83c(%rbp)
lea    -0x810(%rbp),%rax
mov    -0x830(%rbp),%rcx
mov    -0x820(%rbp),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x818(%rbp)
jmp    11ee <load_commands+0x6e>
mov    -0x834(%rbp),%edi
call   1050 <close@plt>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_commands>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    %rdi,0x8(%rsp)
call   10a0 <open@plt>
cmp    $0xffffffff,%eax
je     12f9 <load_commands+0x169>
mov    %eax,%r12d
lea    0x10(%rsp),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0x800,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1291 <load_commands+0x101>
xor    %r13d,%r13d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rsp,%rbx,1),%rcx
add    $0x10,%rcx
mov    %eax,%r15d
add    %rcx,%r15
mov    %r15d,%edx
sub    %ebp,%edx
mov    %rbp,%rdi
mov    $0xa,%esi
call   1070 <memchr@plt>
test   %rax,%rax
je     12cf <load_commands+0x13f>
mov    %rax,%r14
nopl   0x0(%rax)
movb   $0x0,(%r14)
mov    %rbp,%rdi
call   1040 <parse_cmd_line@plt>
test   %eax,%eax
je     12ab <load_commands+0x11b>
mov    %r14,%rbp
add    $0x1,%rbp
mov    %r15,%rbx
sub    %rbp,%rbx
mov    %rbp,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   1070 <memchr@plt>
mov    %rax,%r14
add    $0x1,%r13d
test   %rax,%rax
jne    1220 <load_commands+0x90>
lea    0x10(%rsp),%r14
cmp    %r14,%rbp
je     12cf <load_commands+0x13f>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   1090 <memmove@plt>
mov    $0x800,%edx
sub    %ebx,%edx
lea    (%rsp,%rbx,1),%rsi
add    $0x10,%rsi
mov    %r12d,%edi
call   1080 <read@plt>
test   %eax,%eax
mov    %r14,%rbp
jg     11f0 <load_commands+0x60>
mov    %r12d,%edi
call   1060 <close@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r13d
lea    0xd4a(%rip),%rdi
mov    %r13d,%esi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xd50(%rip),%rdi
mov    $0x800,%esi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
lea    0xd51(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [42 x i8] c"Cannot open alcatest.cmd, terminating...\0A\00"
@.str.1 = [38 x i8] c"ERROR: syntax error at line %d in %s\0A\00"
@.str.2 = [43 x i8] c"ERROR: a line exceed %d characters in %s.\0A\00"
define void @load_commands(i8* %0) {
%2 = alloca i8*
%3 = alloca [2048 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %2
%12 = load i8*, i8** %2
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %1
store i32 0, i32* %11
store i32 2048, i32* %10
%21 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
store i8* %21, i8** %4
br label %22
22: ; preds = %70, %20
%23 = load i32, i32* %8
%24 = load i8*, i8** %4
%25 = load i32, i32* %10
%26 = call i32 @read(i32 %23, i8* %24, i32 %25)
store i32 %26, i32* %9
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %94
28: ; preds = %22
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
store i8* %29, i8** %5
%30 = load i8*, i8** %4
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8* %33, i8** %7
br label %34
34: ; preds = %57, %28
%35 = load i8*, i8** %5
%36 = load i8*, i8** %7
%37 = load i8*, i8** %5
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
%42 = call i64 @memchr(i8* %35, i8 signext 10, i32 %41)
%43 = inttoptr i64 %42 to i8*
store i8* %43, i8** %6
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %60
45: ; preds = %34
%46 = load i8*, i8** %6
store i8 0, i8* %46
%47 = load i32, i32* %11
%48 = add nsw i32 %47, 1
store i32 %48, i32* %11
%49 = load i8*, i8** %5
%50 = call i32 @parse_cmd_line(i8* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %45
%53 = load i32, i32* %11
%54 = load i8*, i8** %2
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %53, i8* %54)
%56 = call i32 @exit(i32 2)
unreachable
57: ; preds = %45
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i64 1
store i8* %59, i8** %5
br label %34
60: ; preds = %34
%61 = load i8*, i8** %5
%62 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%63 = icmp eq i8* %61, %62
br i1 %63, label %64, label %70
64: ; preds = %60
%65 = load i8*, i8** %2
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 2048, i8* %65)
%67 = load i32, i32* %8
%68 = call i32 @close(i32 %67)
%69 = call i32 @exit(i32 2)
unreachable
70: ; preds = %60
%71 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%72 = load i8*, i8** %5
%73 = load i8*, i8** %7
%74 = load i8*, i8** %5
%75 = ptrtoint i8* %73 to i64
%76 = ptrtoint i8* %74 to i64
%77 = sub i64 %75, %76
%78 = trunc i64 %77 to i32
%79 = call i32 @memmove(i8* %71, i8* %72, i32 %78)
%80 = load i8*, i8** %7
%81 = load i8*, i8** %5
%82 = ptrtoint i8* %80 to i64
%83 = ptrtoint i8* %81 to i64
%84 = sub i64 %82, %83
%85 = sub nsw i64 2048, %84
%86 = trunc i64 %85 to i32
store i32 %86, i32* %10
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%88 = load i8*, i8** %7
%89 = load i8*, i8** %5
%90 = ptrtoint i8* %88 to i64
%91 = ptrtoint i8* %89 to i64
%92 = sub i64 %90, %91
%93 = getelementptr inbounds i8, i8* %87, i64 %92
store i8* %93, i8** %4
br label %22
94: ; preds = %22
%95 = load i32, i32* %8
%96 = call i32 @close(i32 %95)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [38 x i8] c"ERROR: syntax error at line %d in %s\0A\00"
@.str.2 = [43 x i8] c"ERROR: a line exceed %d characters in %s.\0A\00"
@str = [41 x i8] c"Cannot open alcatest.cmd, terminating...\00"
define void @load_commands(i8* %0) {
%2 = alloca [2048 x i8]
%3 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = call i32 @read(i32 %5, i8* %3, i32 2048)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %58
10: ; preds = %7
%11 = ptrtoint [2048 x i8]* %2 to i64
br label %15
12: ; preds = %1
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %10, %52
%16 = phi i32 [ %8, %10 ], [ %56, %52 ]
%17 = phi i32 [ 0, %10 ], [ %38, %52 ]
%18 = phi i64 [ 0, %10 ], [ %29, %52 ]
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %18
%20 = zext i32 %16 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = ptrtoint i8* %21 to i64
%23 = sub i64 %22, %11
%24 = trunc i64 %23 to i32
%25 = call i64 @memchr(i8* %3, i8 signext 10, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %48, label %33
27: ; preds = %33
%28 = ptrtoint i8* %41 to i64
%29 = sub i64 %22, %28
%30 = trunc i64 %29 to i32
%31 = call i64 @memchr(i8* %41, i8 signext 10, i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %45, label %33
33: ; preds = %15, %27
%34 = phi i64 [ %31, %27 ], [ %25, %15 ]
%35 = phi i32 [ %38, %27 ], [ %17, %15 ]
%36 = phi i8* [ %41, %27 ], [ %3, %15 ]
%37 = inttoptr i64 %34 to i8*
store i8 0, i8* %37
%38 = add nsw i32 %35, 1
%39 = call i32 @parse_cmd_line(i8* %36)
%40 = icmp eq i32 %39, 0
%41 = getelementptr inbounds i8, i8* %37, i64 1
br i1 %40, label %42, label %27
42: ; preds = %33
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %38, i8* %0)
%44 = call i32 @exit(i32 2)
unreachable
45: ; preds = %27
%46 = trunc i64 %29 to i32
%47 = icmp eq i8* %41, %3
br i1 %47, label %48, label %52
48: ; preds = %15, %45
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 2048, i8* %0)
%50 = call i32 @close(i32 %5)
%51 = call i32 @exit(i32 2)
unreachable
52: ; preds = %45
%53 = call i32 @memmove(i8* %3, i8* %41, i32 %46)
%54 = sub i32 2048, %46
%55 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 %29
%56 = call i32 @read(i32 %5, i8* %55, i32 %54)
%57 = icmp sgt i32 %56, 0
br i1 %57, label %15, label %58
58: ; preds = %52, %7
%59 = call i32 @close(i32 %5)
ret void
}