#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct stat {
  int /*<<< orphan*/ st_size;
};
struct TYPE_4__ {
  scalar_t__ *e_ident;
  int e_shnum;
  int e_shoff;
  int e_shentsize;
};
struct TYPE_3__ {
  scalar_t__ sh_type;
  int sh_flags;
  int sh_offset;
  int /*<<< orphan*/ sh_size;
  int /*<<< orphan*/ sh_addr;
};
typedef TYPE_1__ Elf64_Shdr;
typedef TYPE_2__ Elf64_Ehdr;

/* Variables and functions */
size_t EI_CLASS;
size_t EI_DATA;
scalar_t__ ELFCLASS64;
scalar_t__ ELFDATA2LSB;
int /*<<< orphan*/ ELFMAG;
int EXIT_FAILURE;
int EXIT_SUCCESS;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ SELFMAG;
int SHF_EXECINSTR;
scalar_t__ SHT_PROGBITS;
int check_code(int /*<<< orphan*/, void *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
scalar_t__ memcmp(scalar_t__ *, int /*<<< orphan*/, int /*<<< orphan*/);
void *mmap(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/,
           int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ munmap(void *, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int vmlinux_fd, status, err, i;
  const char *vmlinux_path;
  struct stat st;
  Elf64_Ehdr *eh;
  Elf64_Shdr *sh;
  void *vmlinux;
  status = EXIT_FAILURE;
  if (argc < 2) {
    usage(stderr);
    goto out_ret;
  }
  vmlinux_path = argv[1];
  vmlinux_fd = open(vmlinux_path, O_RDONLY);
  if (vmlinux_fd == -1) {
    perror("Unable to open vmlinux");
    goto out_ret;
  }
  err = fstat(vmlinux_fd, &st);
  if (err) {
    perror("Unable to stat vmlinux");
    goto out_close;
  }
  vmlinux = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, vmlinux_fd, 0);
  if (vmlinux == MAP_FAILED) {
    perror("Unable to mmap vmlinux");
    goto out_close;
  }
  eh = vmlinux;
  if (memcmp(eh->e_ident, ELFMAG, SELFMAG)) {
    fprintf(stderr, "vmlinux is not an ELF?\n");
    goto out_munmap;
  }
  if (eh->e_ident[EI_CLASS] != ELFCLASS64) {
    fprintf(stderr, "vmlinux is not 64b?\n");
    goto out_munmap;
  }
  if (eh->e_ident[EI_DATA] != ELFDATA2LSB) {
    fprintf(stderr, "vmlinux is not little endian?\n");
    goto out_munmap;
  }
  for (i = 0; i < (eh->e_shnum); i++) {
    sh = vmlinux + (eh->e_shoff) + (i * (eh->e_shentsize));
    if (sh->sh_type != SHT_PROGBITS)
      continue;
    if (!(sh->sh_flags & SHF_EXECINSTR))
      continue;
    err = check_code((sh->sh_addr), vmlinux + (sh->sh_offset), (sh->sh_size));
    if (err)
      goto out_munmap;
  }
  status = EXIT_SUCCESS;
out_munmap:
  munmap(vmlinux, st.st_size);
out_close:
  close(vmlinux_fd);
out_ret:
  fprintf(stdout, "loongson3-llsc-check returns %s\n",
          status ? "failure" : "success");
  return status;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x3f>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
jmp    143d <main+0x29d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    121b <main+0x7b>
lea    0xdef(%rip),%rdi
call   10b0 <perror@plt>
jmp    143d <main+0x29d>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   10c0 <fstat@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1245 <main+0xa5>
lea    0xddc(%rip),%rdi
call   10b0 <perror@plt>
jmp    1435 <main+0x295>
mov    -0x30(%rbp),%esi
mov    0x2da9(%rip),%rax
mov    (%rax),%edx
mov    0x2d18(%rip),%rax
mov    (%rax),%ecx
mov    -0x14(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    0x2cef(%rip),%rcx
cmp    (%rcx),%rax
jne    1293 <main+0xf3>
lea    0xda5(%rip),%rdi
call   10b0 <perror@plt>
jmp    1435 <main+0x295>
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    0x2d2f(%rip),%rax
mov    (%rax),%esi
mov    0x2cde(%rip),%rax
mov    (%rax),%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     12df <main+0x13f>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1429 <main+0x289>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0x2cbb(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2cc5(%rip),%rcx
cmp    (%rcx),%rax
je     1320 <main+0x180>
mov    0x2c95(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1429 <main+0x289>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0x2c8a(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2cac(%rip),%rcx
cmp    (%rcx),%rax
je     1361 <main+0x1c1>
mov    0x2c54(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1429 <main+0x289>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x38(%rbp),%rcx
cmp    0x8(%rcx),%eax
jge    141d <main+0x27d>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
movslq 0xc(%rcx),%rcx
add    %rcx,%rax
mov    -0x20(%rbp),%ecx
mov    -0x38(%rbp),%rdx
imul   0x10(%rdx),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
mov    0x2bee(%rip),%rcx
cmp    (%rcx),%rax
je     13b8 <main+0x218>
jmp    140f <main+0x26f>
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2c02(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    13d6 <main+0x236>
jmp    140f <main+0x26f>
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rax
movslq 0xc(%rax),%rax
add    %rax,%rsi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edx
call   10a0 <check_code@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     140a <main+0x26a>
jmp    1429 <main+0x289>
jmp    140f <main+0x26f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1368 <main+0x1c8>
mov    0x2b54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x30(%rbp),%esi
call   1070 <munmap@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2b3c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%ecx
lea    0xc6a(%rip),%rdx
lea    0xc5b(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xc2c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2dd6(%rip),%rax
mov    (%rax),%r13d
cmp    $0x1,%edi
jg     11cd <main+0x2d>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
jmp    1361 <main+0x1c1>
mov    0x8(%rsi),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     13ab <main+0x20b>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
call   10c0 <fstat@plt>
test   %eax,%eax
jne    13b9 <main+0x219>
mov    (%rsp),%r14d
mov    0x2df0(%rip),%rax
mov    (%rax),%edx
mov    0x2d5f(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %r14d,%esi
mov    %r15d,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbp
mov    0x2d3b(%rip),%rax
cmp    (%rax),%rbp
je     13c7 <main+0x227>
mov    0x0(%rbp),%rdi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
mov    0x2d46(%rip),%rax
mov    (%rax),%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     126b <main+0xcb>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
jmp    1347 <main+0x1a7>
mov    0x0(%rbp),%rax
mov    0x2d32(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
mov    0x2d3c(%rip),%rdx
cmp    (%rdx),%rcx
jne    1325 <main+0x185>
mov    0x2d24(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    0x2d46(%rip),%rcx
cmp    (%rcx),%rax
jne    1337 <main+0x197>
mov    0x8(%rbp),%edx
test   %edx,%edx
jle    139f <main+0x1ff>
mov    0x2cdb(%rip),%rax
mov    (%rax),%rcx
xor    %ebx,%ebx
mov    0x2cff(%rip),%r12
jmp    12db <main+0x13b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %edx,%ebx
jge    139f <main+0x1ff>
movslq 0xc(%rbp),%rsi
add    %rbp,%rsi
movslq 0x10(%rbp),%rdi
movslq %ebx,%rax
imul   %rdi,%rax
cmp    %rcx,(%rax,%rsi,1)
jne    12d0 <main+0x130>
mov    (%r12),%edi
test   %edi,0x8(%rsi,%rax,1)
je     12d0 <main+0x130>
mov    0x10(%rsi,%rax,1),%edx
mov    0x14(%rsi,%rax,1),%edi
movslq 0xc(%rsi,%rax,1),%rsi
add    %rbp,%rsi
call   10a0 <check_code@plt>
test   %eax,%eax
jne    134e <main+0x1ae>
mov    0x2c7b(%rip),%rax
mov    (%rax),%rcx
mov    0x8(%rbp),%edx
jmp    12d0 <main+0x130>
mov    0x2c74(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
jmp    1347 <main+0x1a7>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbp,%rdi
mov    %r14d,%esi
call   1070 <munmap@plt>
mov    %r15d,%edi
call   1040 <close@plt>
mov    0x2c18(%rip),%rax
mov    (%rax),%edi
test   %r13d,%r13d
lea    0xd46(%rip),%rax
lea    0xd37(%rip),%rdx
cmove  %rax,%rdx
lea    0xd0b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd2(%rip),%rax
mov    (%rax),%r13d
jmp    134e <main+0x1ae>
lea    0xc4e(%rip),%rdi
call   10b0 <perror@plt>
jmp    1361 <main+0x1c1>
lea    0xc57(%rip),%rdi
call   10b0 <perror@plt>
jmp    1359 <main+0x1b9>
lea    0xc60(%rip),%rdi
call   10b0 <perror@plt>
jmp    1359 <main+0x1b9>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.TYPE_4__ = type { i64*, i32, i32, i32 }
%struct.TYPE_3__ = type { i64, i32, i32, i32, i32 }
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@O_RDONLY = global i32 0
@.str = [23 x i8] c"Unable to open vmlinux\00"
@.str.1 = [23 x i8] c"Unable to stat vmlinux\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [23 x i8] c"Unable to mmap vmlinux\00"
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@.str.3 = [24 x i8] c"vmlinux is not an ELF?\0A\00"
@EI_CLASS = global i64 0
@ELFCLASS64 = global i64 0
@.str.4 = [21 x i8] c"vmlinux is not 64b?\0A\00"
@EI_DATA = global i64 0
@ELFDATA2LSB = global i64 0
@.str.5 = [31 x i8] c"vmlinux is not little endian?\0A\00"
@SHT_PROGBITS = global i64 0
@SHF_EXECINSTR = global i32 0
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@.str.6 = [33 x i8] c"loongson3-llsc-check returns %s\0A\00"
@.str.7 = [8 x i8] c"failure\00"
@.str.8 = [8 x i8] c"success\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca %struct.stat
%12 = alloca %struct.TYPE_4__*
%13 = alloca %struct.TYPE_3__*
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %7
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 2
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 @usage(i32 %19)
br label %155
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %10
%25 = load i8*, i8** %10
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %155
32: ; preds = %21
%33 = load i32, i32* %6
%34 = call i32 @fstat(i32 %33, %struct.stat* %11)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %152
39: ; preds = %32
%40 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%41 = load i32, i32* %40
%42 = load i32, i32* @PROT_READ
%43 = load i32, i32* @MAP_PRIVATE
%44 = load i32, i32* %6
%45 = call i8* @mmap(i32* null, i32 %41, i32 %42, i32 %43, i32 %44, i32 0)
store i8* %45, i8** %14
%46 = load i8*, i8** %14
%47 = load i8*, i8** @MAP_FAILED
%48 = icmp eq i8* %46, %47
br i1 %48, label %49, label %51
49: ; preds = %39
%50 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %152
51: ; preds = %39
%52 = load i8*, i8** %14
%53 = bitcast i8* %52 to %struct.TYPE_4__*
store %struct.TYPE_4__* %53, %struct.TYPE_4__** %12
%54 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%55 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %54, i32 0, i32 0
%56 = load i64*, i64** %55
%57 = load i32, i32* @ELFMAG
%58 = load i32, i32* @SELFMAG
%59 = call i64 @memcmp(i64* %56, i32 %57, i32 %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %51
%62 = load i32, i32* @stderr
%63 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %147
64: ; preds = %51
%65 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%66 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %65, i32 0, i32 0
%67 = load i64*, i64** %66
%68 = load i64, i64* @EI_CLASS
%69 = getelementptr inbounds i64, i64* %67, i64 %68
%70 = load i64, i64* %69
%71 = load i64, i64* @ELFCLASS64
%72 = icmp ne i64 %70, %71
br i1 %72, label %73, label %76
73: ; preds = %64
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %147
76: ; preds = %64
%77 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%78 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %77, i32 0, i32 0
%79 = load i64*, i64** %78
%80 = load i64, i64* @EI_DATA
%81 = getelementptr inbounds i64, i64* %79, i64 %80
%82 = load i64, i64* %81
%83 = load i64, i64* @ELFDATA2LSB
%84 = icmp ne i64 %82, %83
br i1 %84, label %85, label %88
85: ; preds = %76
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %147
88: ; preds = %76
store i32 0, i32* %9
br label %89
89: ; preds = %142, %88
%90 = load i32, i32* %9
%91 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%92 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %91, i32 0, i32 1
%93 = load i32, i32* %92
%94 = icmp slt i32 %90, %93
br i1 %94, label %95, label %145
95: ; preds = %89
%96 = load i8*, i8** %14
%97 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%98 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %97, i32 0, i32 2
%99 = load i32, i32* %98
%100 = sext i32 %99 to i64
%101 = getelementptr i8, i8* %96, i64 %100
%102 = load i32, i32* %9
%103 = load %struct.TYPE_4__*, %struct.TYPE_4__** %12
%104 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %103, i32 0, i32 3
%105 = load i32, i32* %104
%106 = mul nsw i32 %102, %105
%107 = sext i32 %106 to i64
%108 = getelementptr i8, i8* %101, i64 %107
%109 = bitcast i8* %108 to %struct.TYPE_3__*
store %struct.TYPE_3__* %109, %struct.TYPE_3__** %13
%110 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%111 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %110, i32 0, i32 0
%112 = load i64, i64* %111
%113 = load i64, i64* @SHT_PROGBITS
%114 = icmp ne i64 %112, %113
br i1 %114, label %115, label %116
115: ; preds = %95
br label %142
116: ; preds = %95
%117 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%118 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %117, i32 0, i32 1
%119 = load i32, i32* %118
%120 = load i32, i32* @SHF_EXECINSTR
%121 = and i32 %119, %120
%122 = icmp ne i32 %121, 0
br i1 %122, label %124, label %123
123: ; preds = %116
br label %142
124: ; preds = %116
%125 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%126 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %125, i32 0, i32 4
%127 = load i32, i32* %126
%128 = load i8*, i8** %14
%129 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%130 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %129, i32 0, i32 2
%131 = load i32, i32* %130
%132 = sext i32 %131 to i64
%133 = getelementptr i8, i8* %128, i64 %132
%134 = load %struct.TYPE_3__*, %struct.TYPE_3__** %13
%135 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %134, i32 0, i32 3
%136 = load i32, i32* %135
%137 = call i32 @check_code(i32 %127, i8* %133, i32 %136)
store i32 %137, i32* %8
%138 = load i32, i32* %8
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %141
140: ; preds = %124
br label %147
141: ; preds = %124
br label %142
142: ; preds = %141, %123, %115
%143 = load i32, i32* %9
%144 = add nsw i32 %143, 1
store i32 %144, i32* %9
br label %89
145: ; preds = %89
%146 = load i32, i32* @EXIT_SUCCESS
store i32 %146, i32* %7
br label %147
147: ; preds = %145, %140, %85, %73, %61
%148 = load i8*, i8** %14
%149 = getelementptr inbounds %struct.stat, %struct.stat* %11, i32 0, i32 0
%150 = load i32, i32* %149
%151 = call i32 @munmap(i8* %148, i32 %150)
br label %152
152: ; preds = %147, %49, %37
%153 = load i32, i32* %6
%154 = call i32 @close(i32 %153)
br label %155
155: ; preds = %152, %30, %18
%156 = load i32, i32* @stdout
%157 = load i32, i32* %7
%158 = icmp ne i32 %157, 0
%159 = zext i1 %158 to i64
%160 = select i1 %158, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0)
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %160)
%162 = load i32, i32* %7
ret i32 %162
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@O_RDONLY = global i32 0
@.str = [23 x i8] c"Unable to open vmlinux\00"
@.str.1 = [23 x i8] c"Unable to stat vmlinux\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [23 x i8] c"Unable to mmap vmlinux\00"
@ELFMAG = global i32 0
@SELFMAG = global i32 0
@.str.3 = [24 x i8] c"vmlinux is not an ELF?\0A\00"
@EI_CLASS = global i64 0
@ELFCLASS64 = global i64 0
@.str.4 = [21 x i8] c"vmlinux is not 64b?\0A\00"
@EI_DATA = global i64 0
@ELFDATA2LSB = global i64 0
@.str.5 = [31 x i8] c"vmlinux is not little endian?\0A\00"
@SHT_PROGBITS = global i64 0
@SHF_EXECINSTR = global i32 0
@EXIT_SUCCESS = global i32 0
@stdout = global i32 0
@.str.6 = [33 x i8] c"loongson3-llsc-check returns %s\0A\00"
@.str.7 = [8 x i8] c"failure\00"
@.str.8 = [8 x i8] c"success\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = load i32, i32* @EXIT_FAILURE
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @usage(i32 %8)
br label %124
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %124
18: ; preds = %10
%19 = call i32 @fstat(i32 %14, %struct.stat* %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %121
23: ; preds = %18
%24 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @MAP_PRIVATE
%28 = tail call i8* @mmap(i32* null, i32 %25, i32 %26, i32 %27, i32 %14, i32 0)
%29 = load i8*, i8** @MAP_FAILED
%30 = icmp eq i8* %28, %29
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %121
33: ; preds = %23
%34 = bitcast i8* %28 to i64**
%35 = load i64*, i64** %34
%36 = load i32, i32* @ELFMAG
%37 = load i32, i32* @SELFMAG
%38 = tail call i64 @memcmp(i64* %35, i32 %36, i32 %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %118
43: ; preds = %33
%44 = load i64*, i64** %34
%45 = load i64, i64* @EI_CLASS
%46 = getelementptr inbounds i64, i64* %44, i64 %45
%47 = load i64, i64* %46
%48 = load i64, i64* @ELFCLASS64
%49 = icmp eq i64 %47, %48
br i1 %49, label %53, label %50
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %118
53: ; preds = %43
%54 = load i64, i64* @EI_DATA
%55 = getelementptr inbounds i64, i64* %44, i64 %54
%56 = load i64, i64* %55
%57 = load i64, i64* @ELFDATA2LSB
%58 = icmp eq i64 %56, %57
br i1 %58, label %59, label %70
59: ; preds = %53
%60 = getelementptr inbounds i8, i8* %28, i64 8
%61 = bitcast i8* %60 to i32*
%62 = load i32, i32* %61
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %116
64: ; preds = %59
%65 = getelementptr inbounds i8, i8* %28, i64 12
%66 = bitcast i8* %65 to i32*
%67 = getelementptr inbounds i8, i8* %28, i64 16
%68 = bitcast i8* %67 to i32*
%69 = load i64, i64* @SHT_PROGBITS
br label %73
70: ; preds = %53
%71 = load i32, i32* @stderr
%72 = tail call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %118
73: ; preds = %64, %111
%74 = phi i32 [ %62, %64 ], [ %112, %111 ]
%75 = phi i64 [ %69, %64 ], [ %113, %111 ]
%76 = phi i32 [ 0, %64 ], [ %114, %111 ]
%77 = load i32, i32* %66
%78 = sext i32 %77 to i64
%79 = getelementptr i8, i8* %28, i64 %78
%80 = load i32, i32* %68
%81 = mul nsw i32 %80, %76
%82 = sext i32 %81 to i64
%83 = getelementptr i8, i8* %79, i64 %82
%84 = bitcast i8* %83 to i64*
%85 = load i64, i64* %84
%86 = icmp eq i64 %85, %75
br i1 %86, label %87, label %111
87: ; preds = %73
%88 = getelementptr inbounds i8, i8* %83, i64 8
%89 = bitcast i8* %88 to i32*
%90 = load i32, i32* %89
%91 = load i32, i32* @SHF_EXECINSTR
%92 = and i32 %91, %90
%93 = icmp eq i32 %92, 0
br i1 %93, label %111, label %94
94: ; preds = %87
%95 = getelementptr inbounds i8, i8* %83, i64 20
%96 = bitcast i8* %95 to i32*
%97 = load i32, i32* %96
%98 = getelementptr inbounds i8, i8* %83, i64 12
%99 = bitcast i8* %98 to i32*
%100 = load i32, i32* %99
%101 = sext i32 %100 to i64
%102 = getelementptr i8, i8* %28, i64 %101
%103 = getelementptr inbounds i8, i8* %83, i64 16
%104 = bitcast i8* %103 to i32*
%105 = load i32, i32* %104
%106 = tail call i32 @check_code(i32 %97, i8* %102, i32 %105)
%107 = icmp eq i32 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %94
%109 = load i64, i64* @SHT_PROGBITS
%110 = load i32, i32* %61
br label %111
111: ; preds = %108, %87, %73
%112 = phi i32 [ %110, %108 ], [ %74, %87 ], [ %74, %73 ]
%113 = phi i64 [ %109, %108 ], [ %75, %87 ], [ %75, %73 ]
%114 = add nuw nsw i32 %76, 1
%115 = icmp slt i32 %114, %112
br i1 %115, label %73, label %116
116: ; preds = %111, %59
%117 = load i32, i32* @EXIT_SUCCESS
br label %118
118: ; preds = %94, %116, %70, %50, %40
%119 = phi i32 [ %5, %40 ], [ %5, %50 ], [ %5, %70 ], [ %117, %116 ], [ %5, %94 ]
%120 = tail call i32 @munmap(i8* %28, i32 %25)
br label %121
121: ; preds = %118, %31, %21
%122 = phi i32 [ %5, %21 ], [ %5, %31 ], [ %119, %118 ]
%123 = tail call i32 @close(i32 %14)
br label %124
124: ; preds = %121, %16, %7
%125 = phi i32 [ %5, %7 ], [ %5, %16 ], [ %122, %121 ]
%126 = load i32, i32* @stdout
%127 = icmp eq i32 %125, 0
%128 = select i1 %127, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%129 = tail call i32 (i32, i8*, ...) @fprintf(i32 %126, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %128)
ret i32 %125
}