#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int /*<<< orphan*/ Elf32_Ehdr;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
int fstat(int, struct stat *);
int /*<<< orphan*/ is_elf(int /*<<< orphan*/ *);
int /*<<< orphan*/ is_epiphany_exec_elf(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*/ process_elf(void *, unsigned int);
int /*<<< orphan*/ warnx(char *, char const *);
void dump_group(const char *executable, unsigned row, unsigned col,
                unsigned rows, unsigned cols) {
  unsigned int i, j;
  int fd;
  struct stat st;
  void *file;
  fd = open(executable, O_RDONLY);
  if (fd == -1)
    err(EXIT_FAILURE, "ERROR: Can't open executable file \"%s\".", executable);
  if (fstat(fd, &st) == -1)
    err(EXIT_FAILURE, "ERROR: Can't stat file \"%s\".", executable);
  file = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
  if (file == MAP_FAILED)
    err(EXIT_FAILURE, "ERROR: Can't mmap file \"%s\".", executable);
  if (!is_elf((Elf32_Ehdr *)file))
    errx(EXIT_FAILURE, "%s is not an elf file.", executable);
  if (!is_epiphany_exec_elf((Elf32_Ehdr *)file))
    warnx("%s is not an Epiphany elf file.\n", executable);
  for (i = row; i < row + rows; i++) {
    for (j = col; j < col + cols; j++) {
      if (!process_elf(file, (((i) << 6) | (j)))) {
        errx(EXIT_FAILURE, "ERROR: Can't load executable file \"%s\".",
             executable);
      }
    }
  }
  munmap(file, st.st_size);
  close(fd);
}


x86 assembly (clang, -O0):
<dump_group>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e0c(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1201 <dump_group+0x51>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe04(%rip),%rsi
call   1080 <err@plt>
mov    -0x24(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    122f <dump_group+0x7f>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdfe(%rip),%rsi
call   1080 <err@plt>
mov    -0x28(%rbp),%esi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
mov    0x2d86(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%rax
jne    1285 <dump_group+0xd5>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc5(%rip),%rsi
call   1080 <err@plt>
mov    -0x30(%rbp),%rdi
call   1030 <is_elf@plt>
cmp    $0x0,%eax
jne    12b0 <dump_group+0x100>
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdb7(%rip),%rsi
call   1050 <errx@plt>
mov    -0x30(%rbp),%rdi
call   10c0 <is_epiphany_exec_elf@plt>
cmp    $0x0,%eax
jne    12d2 <dump_group+0x122>
mov    -0x8(%rbp),%rsi
lea    0xdac(%rip),%rdi
call   1060 <warnx@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0xc(%rbp),%ecx
add    -0x14(%rbp),%ecx
cmp    %ecx,%eax
jae    135a <dump_group+0x1aa>
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0x18(%rbp),%ecx
cmp    %ecx,%eax
jae    1347 <dump_group+0x197>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%esi
shl    $0x6,%esi
or     -0x20(%rbp),%esi
call   10b0 <process_elf@plt>
cmp    $0x0,%eax
jne    1334 <dump_group+0x184>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd6b(%rip),%rsi
call   1050 <errx@plt>
jmp    1339 <dump_group+0x189>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12ef <dump_group+0x13f>
jmp    134c <dump_group+0x19c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12d8 <dump_group+0x128>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1090 <munmap@plt>
mov    -0x24(%rbp),%edi
call   1070 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_group>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8,0x30(%rsp)
mov    %ecx,%ebx
mov    %rdx,0x10(%rsp)
mov    %esi,0x4(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    %rdi,0x8(%rsp)
call   10a0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1202 <dump_group+0x52>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1080 <err@plt>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
call   10d0 <fstat@plt>
cmp    $0xffffffff,%eax
jne    122d <dump_group+0x7d>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1080 <err@plt>
mov    0x18(%rsp),%esi
mov    0x2dc0(%rip),%rax
mov    (%rax),%edx
mov    0x2d87(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    %esi,0x20(%rsp)
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    %rax,%r13
mov    0x2d62(%rip),%rax
cmp    (%rax),%r13
jne    127d <dump_group+0xcd>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xdd2(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1080 <err@plt>
mov    %r13,%rdi
call   1030 <is_elf@plt>
test   %eax,%eax
jne    12a3 <dump_group+0xf3>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1050 <errx@plt>
mov    %ebp,0x24(%rsp)
mov    %r13,%rdi
call   10c0 <is_epiphany_exec_elf@plt>
test   %eax,%eax
jne    12c4 <dump_group+0x114>
lea    0xdbf(%rip),%rdi
mov    0x8(%rsp),%rsi
call   1060 <warnx@plt>
mov    0x4(%rsp),%eax
add    %eax,%ebx
mov    %ebx,0x2c(%rsp)
cmp    %eax,%ebx
jbe    136d <dump_group+0x1bd>
mov    0x30(%rsp),%rax
mov    0x10(%rsp),%rcx
add    %ecx,%eax
mov    %eax,0x28(%rsp)
mov    0x2ce3(%rip),%r12
lea    0xda6(%rip),%r14
jmp    1311 <dump_group+0x161>
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
cmp    0x2c(%rsp),%eax
je     136d <dump_group+0x1bd>
mov    0x28(%rsp),%eax
cmp    0x10(%rsp),%eax
jbe    1300 <dump_group+0x150>
mov    0x4(%rsp),%ebp
shl    $0x6,%ebp
mov    0x30(%rsp),%rax
mov    %eax,%ebx
mov    0x10(%rsp),%rax
mov    %eax,%r15d
jmp    1349 <dump_group+0x199>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r15d
add    $0xffffffff,%ebx
je     1300 <dump_group+0x150>
mov    %r15d,%esi
or     %ebp,%esi
mov    %r13,%rdi
call   10b0 <process_elf@plt>
test   %eax,%eax
jne    1340 <dump_group+0x190>
mov    (%r12),%edi
mov    %r14,%rsi
mov    0x8(%rsp),%rdx
call   1050 <errx@plt>
jmp    1340 <dump_group+0x190>
mov    %r13,%rdi
mov    0x20(%rsp),%esi
call   1090 <munmap@plt>
mov    0x24(%rsp),%edi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <close@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [40 x i8] c"ERROR: Can't open executable file \22%s\22.\00"
@.str.1 = [29 x i8] c"ERROR: Can't stat file \22%s\22.\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [29 x i8] c"ERROR: Can't mmap file \22%s\22.\00"
@.str.3 = [23 x i8] c"%s is not an elf file.\00"
@.str.4 = [33 x i8] c"%s is not an Epiphany elf file.\0A\00"
@.str.5 = [40 x i8] c"ERROR: Can't load executable file \22%s\22.\00"
define void @dump_group(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.stat
%15 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%16 = load i8*, i8** %6
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %16, i32 %17)
store i32 %18, i32* %13
%19 = load i32, i32* %13
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %5
%22 = load i32, i32* @EXIT_FAILURE
%23 = load i8*, i8** %6
%24 = call i32 @err(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %21, %5
%26 = load i32, i32* %13
%27 = call i32 @fstat(i32 %26, %struct.stat* %14)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @EXIT_FAILURE
%31 = load i8*, i8** %6
%32 = call i32 @err(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %29, %25
%34 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load i32, i32* @PROT_READ
%37 = load i32, i32* @MAP_PRIVATE
%38 = load i32, i32* %13
%39 = call i8* @mmap(i32* null, i32 %35, i32 %36, i32 %37, i32 %38, i32 0)
store i8* %39, i8** %15
%40 = load i8*, i8** %15
%41 = load i8*, i8** @MAP_FAILED
%42 = icmp eq i8* %40, %41
br i1 %42, label %43, label %47
43: ; preds = %33
%44 = load i32, i32* @EXIT_FAILURE
%45 = load i8*, i8** %6
%46 = call i32 @err(i32 %44, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %43, %33
%48 = load i8*, i8** %15
%49 = bitcast i8* %48 to i32*
%50 = call i32 @is_elf(i32* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %56, label %52
52: ; preds = %47
%53 = load i32, i32* @EXIT_FAILURE
%54 = load i8*, i8** %6
%55 = call i32 @errx(i32 %53, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52, %47
%57 = load i8*, i8** %15
%58 = bitcast i8* %57 to i32*
%59 = call i32 @is_epiphany_exec_elf(i32* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %64, label %61
61: ; preds = %56
%62 = load i8*, i8** %6
%63 = call i32 @warnx(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %61, %56
%65 = load i32, i32* %7
store i32 %65, i32* %11
br label %66
66: ; preds = %97, %64
%67 = load i32, i32* %11
%68 = load i32, i32* %7
%69 = load i32, i32* %9
%70 = add i32 %68, %69
%71 = icmp ult i32 %67, %70
br i1 %71, label %72, label %100
72: ; preds = %66
%73 = load i32, i32* %8
store i32 %73, i32* %12
br label %74
74: ; preds = %93, %72
%75 = load i32, i32* %12
%76 = load i32, i32* %8
%77 = load i32, i32* %10
%78 = add i32 %76, %77
%79 = icmp ult i32 %75, %78
br i1 %79, label %80, label %96
80: ; preds = %74
%81 = load i8*, i8** %15
%82 = load i32, i32* %11
%83 = shl i32 %82, 6
%84 = load i32, i32* %12
%85 = or i32 %83, %84
%86 = call i32 @process_elf(i8* %81, i32 %85)
%87 = icmp ne i32 %86, 0
br i1 %87, label %92, label %88
88: ; preds = %80
%89 = load i32, i32* @EXIT_FAILURE
%90 = load i8*, i8** %6
%91 = call i32 @errx(i32 %89, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %88, %80
br label %93
93: ; preds = %92
%94 = load i32, i32* %12
%95 = add i32 %94, 1
store i32 %95, i32* %12
br label %74
96: ; preds = %74
br label %97
97: ; preds = %96
%98 = load i32, i32* %11
%99 = add i32 %98, 1
store i32 %99, i32* %11
br label %66
100: ; preds = %66
%101 = load i8*, i8** %15
%102 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%103 = load i32, i32* %102
%104 = call i32 @munmap(i8* %101, i32 %103)
%105 = load i32, i32* %13
%106 = call i32 @close(i32 %105)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [40 x i8] c"ERROR: Can't open executable file \22%s\22.\00"
@.str.1 = [29 x i8] c"ERROR: Can't stat file \22%s\22.\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.2 = [29 x i8] c"ERROR: Can't mmap file \22%s\22.\00"
@.str.3 = [23 x i8] c"%s is not an elf file.\00"
@.str.4 = [33 x i8] c"%s is not an Epiphany elf file.\0A\00"
@.str.5 = [40 x i8] c"ERROR: Can't load executable file \22%s\22.\00"
define void @dump_group(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.stat
%7 = bitcast %struct.stat* %6 to i8*
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* %0, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @err(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %14
14: ; preds = %11, %5
%15 = call i32 @fstat(i32 %9, %struct.stat* %6)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @err(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
20: ; preds = %17, %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%22 = load i32, i32* %21
%23 = load i32, i32* @PROT_READ
%24 = load i32, i32* @MAP_PRIVATE
%25 = tail call i8* @mmap(i32* null, i32 %22, i32 %23, i32 %24, i32 %9, i32 0)
%26 = load i8*, i8** @MAP_FAILED
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* @EXIT_FAILURE
%30 = tail call i32 @err(i32 %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %31
31: ; preds = %28, %20
%32 = bitcast i8* %25 to i32*
%33 = tail call i32 @is_elf(i32* %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = load i32, i32* @EXIT_FAILURE
%37 = tail call i32 @errx(i32 %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %38
38: ; preds = %35, %31
%39 = tail call i32 @is_epiphany_exec_elf(i32* %32)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = tail call i32 @warnx(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %43
43: ; preds = %41, %38
%44 = add i32 %3, %1
%45 = icmp ugt i32 %44, %1
br i1 %45, label %46, label %67
46: ; preds = %43
%47 = add i32 %4, %2
%48 = icmp ugt i32 %47, %2
br label %49
49: ; preds = %46, %64
%50 = phi i32 [ %1, %46 ], [ %65, %64 ]
br i1 %48, label %51, label %64
51: ; preds = %49
%52 = shl i32 %50, 6
br label %53
53: ; preds = %51, %61
%54 = phi i32 [ %2, %51 ], [ %62, %61 ]
%55 = or i32 %54, %52
%56 = tail call i32 @process_elf(i8* %25, i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i32, i32* @EXIT_FAILURE
%60 = tail call i32 @errx(i32 %59, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %61
61: ; preds = %53, %58
%62 = add i32 %54, 1
%63 = icmp eq i32 %62, %47
br i1 %63, label %64, label %53
64: ; preds = %61, %49
%65 = add nuw i32 %50, 1
%66 = icmp eq i32 %65, %44
br i1 %66, label %67, label %49
67: ; preds = %64, %43
%68 = tail call i32 @munmap(i8* %25, i32 %22)
%69 = tail call i32 @close(i32 %9)
ret void
}