#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
char *__parse_script(char *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
char *parse_script(const char *name) {
  FILE *fscript;
  int len;
  char *buf;
  int read_len;
  int shmid;
  char *script_buf;
  if (name == NULL) {
    do {
      fprintf(stderr, "(error): ");
      fprintf(stderr, "script: invalid file name(null)\n");
    } while (0);
    return NULL;
  }
  fscript = fopen(name, "rb");
  if (fscript == NULL) {
    do {
      fprintf(stderr, "(error): ");
      fprintf(stderr, "script: can't open %s(%s)\n", name, strerror(errno));
    } while (0);
    return NULL;
  }
  fseek(fscript, 0, SEEK_END);
  len = ftell(fscript);
  fseek(fscript, 0, SEEK_SET);
  buf = malloc(len);
  if (buf == NULL) {
    do {
      fprintf(stderr, "(error): ");
      fprintf(stderr, "script: allocate memory for script data failed(%s)\n",
              strerror(errno));
    } while (0);
    fclose(fscript);
    return NULL;
  }
  read_len = fread(buf, 1, len, fscript);
  if (read_len < len) {
    do {
      fprintf(stdout, "(debug): ");
      fprintf(stdout, "len = %d, read_len = %d, fix me\n", len, read_len);
    } while (0);
  }
  fclose(fscript);
  script_buf = __parse_script(buf, len);
  free(buf);
  return script_buf;
}


x86 assembly (clang, -O0):
<parse_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f7 <parse_script+0x57>
jmp    11bc <parse_script+0x1c>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13b0 <parse_script+0x210>
mov    -0x10(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1279 <parse_script+0xd9>
jmp    121b <parse_script+0x7b>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13b0 <parse_script+0x210>
mov    -0x18(%rbp),%rdi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x1c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1324 <parse_script+0x184>
jmp    12c9 <parse_script+0x129>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
lea    0xd27(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    13b0 <parse_script+0x210>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1386 <parse_script+0x1e6>
jmp    134d <parse_script+0x1ad>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1386 <parse_script+0x1e6>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <__parse_script@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_script>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1283 <parse_script+0xe3>
mov    %rdi,%rbp
lea    0xe70(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12af <parse_script+0x10f>
mov    %rax,%rbx
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r14d
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r14d,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12ee <parse_script+0x14e>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    %r14d,%eax
jge    125d <parse_script+0xbd>
mov    %eax,%r15d
mov    0x2d8d(%rip),%r12
mov    (%r12),%edi
lea    0xe3f(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r12),%edi
lea    0xe37(%rip),%rsi
mov    %r14d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1080 <__parse_script@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
jmp    1334 <parse_script+0x194>
mov    0x2d4e(%rip),%rbx
mov    (%rbx),%edi
lea    0xd6d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd67(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1332 <parse_script+0x192>
mov    0x2d22(%rip),%rbx
mov    (%rbx),%edi
lea    0xd41(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%ebx
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd51(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1332 <parse_script+0x192>
mov    0x2ce3(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xd01(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x0(%rbp),%ebp
mov    0x2cc0(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd2b(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [10 x i8] c"(error): \00"
@.str.1 = [33 x i8] c"script: invalid file name(null)\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [27 x i8] c"script: can't open %s(%s)\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [52 x i8] c"script: allocate memory for script data failed(%s)\0A\00"
@stdout = global i32 0
@.str.5 = [10 x i8] c"(debug): \00"
@.str.6 = [33 x i8] c"len = %d, read_len = %d, fix me\0A\00"
define i8* @parse_script(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %19
12: ; preds = %1
br label %13
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %13
store i8* null, i8** %2
br label %84
19: ; preds = %1
%20 = load i8*, i8** %3
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %4
%22 = load i32*, i32** %4
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %34
24: ; preds = %19
br label %25
25: ; preds = %24
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %3
%30 = load i32, i32* @errno
%31 = call i8* @strerror(i32 %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %29, i8* %31)
br label %33
33: ; preds = %25
store i8* null, i8** %2
br label %84
34: ; preds = %19
%35 = load i32*, i32** %4
%36 = load i32, i32* @SEEK_END
%37 = call i32 @fseek(i32* %35, i32 0, i32 %36)
%38 = load i32*, i32** %4
%39 = call i32 @ftell(i32* %38)
store i32 %39, i32* %5
%40 = load i32*, i32** %4
%41 = load i32, i32* @SEEK_SET
%42 = call i32 @fseek(i32* %40, i32 0, i32 %41)
%43 = load i32, i32* %5
%44 = call i8* @malloc(i32 %43)
store i8* %44, i8** %6
%45 = load i8*, i8** %6
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %58
47: ; preds = %34
br label %48
48: ; preds = %47
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %48
%56 = load i32*, i32** %4
%57 = call i32 @fclose(i32* %56)
store i8* null, i8** %2
br label %84
58: ; preds = %34
%59 = load i8*, i8** %6
%60 = load i32, i32* %5
%61 = load i32*, i32** %4
%62 = call i32 @fread(i8* %59, i32 1, i32 %60, i32* %61)
store i32 %62, i32* %7
%63 = load i32, i32* %7
%64 = load i32, i32* %5
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %75
66: ; preds = %58
br label %67
67: ; preds = %66
%68 = load i32, i32* @stdout
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%70 = load i32, i32* @stdout
%71 = load i32, i32* %5
%72 = load i32, i32* %7
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %71, i32 %72)
br label %74
74: ; preds = %67
br label %75
75: ; preds = %74, %58
%76 = load i32*, i32** %4
%77 = call i32 @fclose(i32* %76)
%78 = load i8*, i8** %6
%79 = load i32, i32* %5
%80 = call i8* @__parse_script(i8* %78, i32 %79)
store i8* %80, i8** %9
%81 = load i8*, i8** %6
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %9
store i8* %83, i8** %2
br label %84
84: ; preds = %75, %55, %33, %18
%85 = load i8*, i8** %2
ret i8* %85
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [10 x i8] c"(error): \00"
@.str.1 = [33 x i8] c"script: invalid file name(null)\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [27 x i8] c"script: can't open %s(%s)\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.4 = [52 x i8] c"script: allocate memory for script data failed(%s)\0A\00"
@stdout = global i32 0
@.str.5 = [10 x i8] c"(debug): \00"
@.str.6 = [33 x i8] c"len = %d, read_len = %d, fix me\0A\00"
define i8* @parse_script(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %8
3: ; preds = %1
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %46
8: ; preds = %1
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %16)
br label %46
18: ; preds = %8
%19 = load i32, i32* @SEEK_END
%20 = tail call i32 @fseek(i32* %9, i32 0, i32 %19)
%21 = tail call i32 @ftell(i32* %9)
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @fseek(i32* %9, i32 0, i32 %22)
%24 = tail call i8* @malloc(i32 %21)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = load i32, i32* @errno
%31 = tail call i8* @strerror(i32 %30)
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = tail call i32 @fclose(i32* %9)
br label %46
34: ; preds = %18
%35 = tail call i32 @fread(i8* %24, i32 1, i32 %21, i32* %9)
%36 = icmp slt i32 %35, %21
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i32, i32* @stdout
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32, i32* @stdout
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %21, i32 %35)
br label %42
42: ; preds = %37, %34
%43 = tail call i32 @fclose(i32* %9)
%44 = tail call i8* @__parse_script(i8* %24, i32 %21)
%45 = tail call i32 @free(i8* %24)
br label %46
46: ; preds = %42, %26, %11, %3
%47 = phi i8* [ null, %3 ], [ null, %11 ], [ null, %26 ], [ %44, %42 ]
ret i8* %47
}