#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 uint32_t;
typedef int /*<<< orphan*/ _nb_labels;
typedef int /*<<< orphan*/ _nb_images;
typedef int /*<<< orphan*/ _magic;
typedef int /*<<< orphan*/ _dim2;
typedef int /*<<< orphan*/ _dim1;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int df_convert_uint32(int);
int /*<<< orphan*/ disp_image(char *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ read(int, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int _fd_images, _fd_labels;
  uint32_t _magic, _nb_images, _dim1, _dim2, _size, _nb, _nb_labels;
  char *_train_images, *_train_labels, *_test_images, *_test_labels, *_image;
  _train_images = "../data/train-images-idx3-ubyte";
  _train_labels = "../data/train-labels-idx1-ubyte";
  _test_images = "../data/t10k-images-idx3-ubyte";
  _test_labels = "../data/t10k-labels-idx1-ubyte";
  if ((_fd_images = open(_train_images, O_RDONLY)) < 0) {
    fprintf(stderr, "%s : cannot open \"%s\" !\n", argv[0], _train_images);
    exit(1);
  }
  if (read(_fd_images, &_magic, sizeof(_magic)) < 0) {
    fprintf(stderr, "%s : error while reading magic number !\n", argv[0]);
    exit(1);
  }
  printf("Magic number  = 0x%08x\n", df_convert_uint32(_magic));
  if (read(_fd_images, &_nb_images, sizeof(_nb_images)) < 0) {
    fprintf(stderr, "%s : error while reading images number !\n", argv[0]);
    exit(1);
  }
  printf("Images number = %10d  (0x%08x)\n", df_convert_uint32(_nb_images),
         df_convert_uint32(_nb_images));
  if (read(_fd_images, &_dim1, sizeof(_dim1)) < 0) {
    fprintf(stderr, "%s : error while reading dimension 1 !\n", argv[0]);
    exit(1);
  }
  if (read(_fd_images, &_dim2, sizeof(_dim2)) < 0) {
    fprintf(stderr, "%s : error while reading dimension 2 !\n", argv[0]);
    exit(1);
  }
  _dim1 = df_convert_uint32(_dim1);
  _dim2 = df_convert_uint32(_dim2);
  printf("Dimension 1 = %10d  (0x%08x)\n", _dim1, _dim1);
  printf("Dimension 2 = %10d  (0x%08x)\n", _dim2, _dim2);
  _size = _dim1 * _dim2;
  if ((_image = (unsigned char *)malloc(_size)) == NULL) {
    fprintf(stderr, "%s : cannot allocate %d bytes for the images !\n", argv[0],
            _size);
    exit(1);
  }
  if ((_fd_labels = open(_train_labels, O_RDONLY)) < 0) {
    fprintf(stderr, "%s : cannot open \"%s\" !\n", argv[0], _train_labels);
    exit(1);
  }
  if (read(_fd_labels, &_magic, sizeof(_magic)) < 0) {
    fprintf(stderr, "%s : error while reading magic number !\n", argv[0]);
    exit(1);
  }
  printf("Magic number  = 0x%08x\n", df_convert_uint32(_magic));
  if (read(_fd_labels, &_nb_labels, sizeof(_nb_labels)) < 0) {
    fprintf(stderr, "%s : error while reading labels number !\n", argv[0]);
    exit(1);
  }
  printf("Labels number = %10d  (0x%08x)\n", df_convert_uint32(_nb_labels),
         df_convert_uint32(_nb_labels));
  for (_nb = 0; _nb < _nb_images; _nb++) {
    if (read(_fd_images, _image, _size) <= 0) {
      fprintf(stderr, "%s : error while reading image !\n", argv[0]);
      exit(1);
    }
    printf("Image %10d read (size = %10d) ...\n", _nb, _size);
    disp_image(_image, _dim1, _dim2);
  }
  close(_fd_labels);
  close(_fd_images);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe68(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xe91(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    121c <main+0x8c>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x40(%rbp),%rcx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1261 <main+0xd1>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    12be <main+0x12e>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe2b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,-0x64(%rbp)
mov    -0x20(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    -0x64(%rbp),%esi
mov    %eax,%edx
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1329 <main+0x199>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    136e <main+0x1de>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x28(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x60(%rbp)
cmp    $0x0,%rax
jne    13f7 <main+0x267>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x48(%rbp),%rdi
mov    0x2be6(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1441 <main+0x2b1>
mov    0x2bbc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x48(%rbp),%rcx
lea    0xc4e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1486 <main+0x2f6>
mov    0x2b73(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xc22(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,%esi
lea    0xc29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x34(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jge    14e3 <main+0x353>
mov    0x2b16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x34(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,-0x68(%rbp)
mov    -0x34(%rbp),%edi
call   1090 <df_convert_uint32@plt>
mov    -0x68(%rbp),%esi
mov    %eax,%edx
lea    0xd06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1590 <main+0x400>
mov    -0x14(%rbp),%edi
mov    -0x60(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    $0x0,%al
call   1050 <read@plt>
cmp    $0x0,%rax
jg     155f <main+0x3cf>
mov    0x2a9a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x30(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x60(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1080 <disp_image@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1510 <main+0x380>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
mov    0x2e40(%rip),%r14
mov    (%r14),%esi
lea    0xe4e(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     141e <main+0x28e>
mov    %eax,%r15d
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
mov    %eax,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     1408 <main+0x278>
mov    0x18(%rsp),%edi
call   1090 <df_convert_uint32@plt>
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x14(%rsp),%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     143e <main+0x2ae>
mov    0x14(%rsp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,%ebx
mov    0x14(%rsp),%edi
call   1090 <df_convert_uint32@plt>
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     1454 <main+0x2c4>
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
mov    %r15d,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     146a <main+0x2da>
mov    0x10(%rsp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,0x10(%rsp)
mov    0xc(%rsp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%edx
lea    0xe9b(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
lea    0xea5(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0xc(%rsp),%ebx
imul   0x10(%rsp),%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1483 <main+0x2f3>
mov    %rax,%rbp
mov    (%r14),%esi
lea    0xd44(%rip),%rdi
call   10a0 <open@plt>
test   %eax,%eax
js     14aa <main+0x31a>
mov    %eax,%r12d
lea    0x18(%rsp),%rsi
mov    $0x4,%edx
mov    %eax,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     1408 <main+0x278>
mov    %r13,0x20(%rsp)
mov    0x18(%rsp),%edi
call   1090 <df_convert_uint32@plt>
lea    0xd65(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x1c(%rsp),%rsi
mov    $0x4,%edx
mov    %r12d,%edi
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
js     14d6 <main+0x346>
mov    0x1c(%rsp),%edi
call   1090 <df_convert_uint32@plt>
mov    %eax,%r14d
mov    0x1c(%rsp),%edi
call   1090 <df_convert_uint32@plt>
lea    0xe6b(%rip),%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0x14(%rsp)
jle    13be <main+0x22e>
lea    0xe93(%rip),%r13
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <read@plt>
test   %rax,%rax
jle    13df <main+0x24f>
mov    %r13,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
mov    %rbp,%rdi
call   1080 <disp_image@plt>
add    $0x1,%r14d
cmp    0x14(%rsp),%r14d
jl     1380 <main+0x1f0>
mov    %r12d,%edi
call   1040 <close@plt>
mov    %r15d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf2(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    (%rax),%rdx
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2bc9(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xc3d(%rip),%rsi
jmp    13f7 <main+0x267>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xc0e(%rip),%rsi
lea    0xbc7(%rip),%rcx
jmp    14c5 <main+0x335>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xc48(%rip),%rsi
jmp    13f7 <main+0x267>
mov    0x2b7d(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xc7c(%rip),%rsi
jmp    13f7 <main+0x267>
mov    0x2b67(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xc8e(%rip),%rsi
jmp    13f7 <main+0x267>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xcd9(%rip),%rsi
mov    %ebx,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2b27(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xb82(%rip),%rsi
lea    0xb5b(%rip),%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2afb(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    (%rax),%rdx
lea    0xcb2(%rip),%rsi
jmp    13f7 <main+0x267>

LLVM IR (-O0):
@.str = [32 x i8] c"../data/train-images-idx3-ubyte\00"
@.str.1 = [32 x i8] c"../data/train-labels-idx1-ubyte\00"
@.str.2 = [31 x i8] c"../data/t10k-images-idx3-ubyte\00"
@.str.3 = [31 x i8] c"../data/t10k-labels-idx1-ubyte\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [25 x i8] c"%s : cannot open \22%s\22 !\0A\00"
@.str.5 = [41 x i8] c"%s : error while reading magic number !\0A\00"
@.str.6 = [24 x i8] c"Magic number = 0x%08x\0A\00"
@.str.7 = [42 x i8] c"%s : error while reading images number !\0A\00"
@.str.8 = [32 x i8] c"Images number = %10d (0x%08x)\0A\00"
@.str.9 = [40 x i8] c"%s : error while reading dimension 1 !\0A\00"
@.str.10 = [40 x i8] c"%s : error while reading dimension 2 !\0A\00"
@.str.11 = [30 x i8] c"Dimension 1 = %10d (0x%08x)\0A\00"
@.str.12 = [30 x i8] c"Dimension 2 = %10d (0x%08x)\0A\00"
@.str.13 = [48 x i8] c"%s : cannot allocate %d bytes for the images !\0A\00"
@.str.14 = [42 x i8] c"%s : error while reading labels number !\0A\00"
@.str.15 = [32 x i8] c"Labels number = %10d (0x%08x)\0A\00"
@.str.16 = [34 x i8] c"%s : error while reading image !\0A\00"
@.str.17 = [35 x i8] c"Image %10d read (size = %10d) ...\0A\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 i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8** %17
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8** %18
%20 = load i8*, i8** %15
%21 = load i32, i32* @O_RDONLY
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %2
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = load i8*, i8** %15
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %28, i8* %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = load i32, i32* %6
%34 = call i64 (i32, ...) @read(i32 %33, i32* %8, i64 4)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 0
%40 = load i8*, i8** %39
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %32
%44 = load i32, i32* %8
%45 = call i32 @df_convert_uint32(i32 %44)
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %6
%48 = call i64 (i32, ...) @read(i32 %47, i32* %9, i64 4)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %57
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %43
%58 = load i32, i32* %9
%59 = call i32 @df_convert_uint32(i32 %58)
%60 = load i32, i32* %9
%61 = call i32 @df_convert_uint32(i32 %60)
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %59, i32 %61)
%63 = load i32, i32* %6
%64 = call i64 (i32, ...) @read(i32 %63, i32* %10, i64 4)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %73
66: ; preds = %57
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8* %70)
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %57
%74 = load i32, i32* %6
%75 = call i64 (i32, ...) @read(i32 %74, i32* %11, i64 4)
%76 = icmp slt i64 %75, 0
br i1 %76, label %77, label %84
77: ; preds = %73
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %73
%85 = load i32, i32* %10
%86 = call i32 @df_convert_uint32(i32 %85)
store i32 %86, i32* %10
%87 = load i32, i32* %11
%88 = call i32 @df_convert_uint32(i32 %87)
store i32 %88, i32* %11
%89 = load i32, i32* %10
%90 = load i32, i32* %10
%91 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i32 %89, i32 %90)
%92 = load i32, i32* %11
%93 = load i32, i32* %11
%94 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 %92, i32 %93)
%95 = load i32, i32* %10
%96 = load i32, i32* %11
%97 = mul nsw i32 %95, %96
store i32 %97, i32* %12
%98 = load i32, i32* %12
%99 = call i64 @malloc(i32 %98)
%100 = inttoptr i64 %99 to i8*
store i8* %100, i8** %19
%101 = icmp eq i8* %100, null
br i1 %101, label %102, label %110
102: ; preds = %84
%103 = load i32, i32* @stderr
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 0
%106 = load i8*, i8** %105
%107 = load i32, i32* %12
%108 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %103, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0), i8* %106, i32 %107)
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %84
%111 = load i8*, i8** %16
%112 = load i32, i32* @O_RDONLY
%113 = call i32 @open(i8* %111, i32 %112)
store i32 %113, i32* %7
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %123
115: ; preds = %110
%116 = load i32, i32* @stderr
%117 = load i8**, i8*** %5
%118 = getelementptr inbounds i8*, i8** %117, i64 0
%119 = load i8*, i8** %118
%120 = load i8*, i8** %16
%121 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %119, i8* %120)
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %110
%124 = load i32, i32* %7
%125 = call i64 (i32, ...) @read(i32 %124, i32* %8, i64 4)
%126 = icmp slt i64 %125, 0
br i1 %126, label %127, label %134
127: ; preds = %123
%128 = load i32, i32* @stderr
%129 = load i8**, i8*** %5
%130 = getelementptr inbounds i8*, i8** %129, i64 0
%131 = load i8*, i8** %130
%132 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %128, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %131)
%133 = call i32 @exit(i32 1)
unreachable
134: ; preds = %123
%135 = load i32, i32* %8
%136 = call i32 @df_convert_uint32(i32 %135)
%137 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %136)
%138 = load i32, i32* %7
%139 = call i64 (i32, ...) @read(i32 %138, i32* %14, i64 4)
%140 = icmp slt i64 %139, 0
br i1 %140, label %141, label %148
141: ; preds = %134
%142 = load i32, i32* @stderr
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 0
%145 = load i8*, i8** %144
%146 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %142, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0), i8* %145)
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %134
%149 = load i32, i32* %14
%150 = call i32 @df_convert_uint32(i32 %149)
%151 = load i32, i32* %14
%152 = call i32 @df_convert_uint32(i32 %151)
%153 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i32 %150, i32 %152)
store i32 0, i32* %13
br label %154
154: ; preds = %179, %148
%155 = load i32, i32* %13
%156 = load i32, i32* %9
%157 = icmp slt i32 %155, %156
br i1 %157, label %158, label %182
158: ; preds = %154
%159 = load i32, i32* %6
%160 = load i8*, i8** %19
%161 = load i32, i32* %12
%162 = call i64 (i32, ...) @read(i32 %159, i8* %160, i32 %161)
%163 = icmp sle i64 %162, 0
br i1 %163, label %164, label %171
164: ; preds = %158
%165 = load i32, i32* @stderr
%166 = load i8**, i8*** %5
%167 = getelementptr inbounds i8*, i8** %166, i64 0
%168 = load i8*, i8** %167
%169 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %165, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %168)
%170 = call i32 @exit(i32 1)
unreachable
171: ; preds = %158
%172 = load i32, i32* %13
%173 = load i32, i32* %12
%174 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i32 %172, i32 %173)
%175 = load i8*, i8** %19
%176 = load i32, i32* %10
%177 = load i32, i32* %11
%178 = call i32 @disp_image(i8* %175, i32 %176, i32 %177)
br label %179
179: ; preds = %171
%180 = load i32, i32* %13
%181 = add nsw i32 %180, 1
store i32 %181, i32* %13
br label %154
182: ; preds = %154
%183 = load i32, i32* %7
%184 = call i32 @close(i32 %183)
%185 = load i32, i32* %6
%186 = call i32 @close(i32 %185)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"../data/train-images-idx3-ubyte\00"
@.str.1 = [32 x i8] c"../data/train-labels-idx1-ubyte\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.4 = [25 x i8] c"%s : cannot open \22%s\22 !\0A\00"
@.str.5 = [41 x i8] c"%s : error while reading magic number !\0A\00"
@.str.6 = [24 x i8] c"Magic number = 0x%08x\0A\00"
@.str.7 = [42 x i8] c"%s : error while reading images number !\0A\00"
@.str.8 = [32 x i8] c"Images number = %10d (0x%08x)\0A\00"
@.str.9 = [40 x i8] c"%s : error while reading dimension 1 !\0A\00"
@.str.10 = [40 x i8] c"%s : error while reading dimension 2 !\0A\00"
@.str.11 = [30 x i8] c"Dimension 1 = %10d (0x%08x)\0A\00"
@.str.12 = [30 x i8] c"Dimension 2 = %10d (0x%08x)\0A\00"
@.str.13 = [48 x i8] c"%s : cannot allocate %d bytes for the images !\0A\00"
@.str.14 = [42 x i8] c"%s : error while reading labels number !\0A\00"
@.str.15 = [32 x i8] c"Labels number = %10d (0x%08x)\0A\00"
@.str.16 = [34 x i8] c"%s : error while reading image !\0A\00"
@.str.17 = [35 x i8] c"Image %10d read (size = %10d) ...\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = call i64 (i32, ...) @read(i32 %14, i32* %3, i64 4)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %1
%27 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %26)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* %3
%31 = call i32 @df_convert_uint32(i32 %30)
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = call i64 (i32, ...) @read(i32 %14, i32* %4, i64 4)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %1
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = load i32, i32* %4
%42 = call i32 @df_convert_uint32(i32 %41)
%43 = load i32, i32* %4
%44 = call i32 @df_convert_uint32(i32 %43)
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i32 %42, i32 %44)
%46 = call i64 (i32, ...) @read(i32 %14, i32* %5, i64 4)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %40
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %1
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0), i8* %50)
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %40
%54 = call i64 (i32, ...) @read(i32 %14, i32* %6, i64 4)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load i32, i32* @stderr
%58 = load i8*, i8** %1
%59 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0), i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %53
%62 = load i32, i32* %5
%63 = call i32 @df_convert_uint32(i32 %62)
store i32 %63, i32* %5
%64 = load i32, i32* %6
%65 = call i32 @df_convert_uint32(i32 %64)
store i32 %65, i32* %6
%66 = load i32, i32* %5
%67 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.11, i64 0, i64 0), i32 %66, i32 %66)
%68 = load i32, i32* %6
%69 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.12, i64 0, i64 0), i32 %68, i32 %68)
%70 = load i32, i32* %5
%71 = load i32, i32* %6
%72 = mul nsw i32 %71, %70
%73 = call i64 @malloc(i32 %72)
%74 = inttoptr i64 %73 to i8*
%75 = icmp eq i64 %73, 0
br i1 %75, label %76, label %81
76: ; preds = %61
%77 = load i32, i32* @stderr
%78 = load i8*, i8** %1
%79 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.13, i64 0, i64 0), i8* %78, i32 %72)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %61
%82 = load i32, i32* @O_RDONLY
%83 = call i32 @open(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %82)
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %81
%86 = load i32, i32* @stderr
%87 = load i8*, i8** %1
%88 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %87, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%89 = call i32 @exit(i32 1)
unreachable
90: ; preds = %81
%91 = call i64 (i32, ...) @read(i32 %83, i32* %3, i64 4)
%92 = icmp slt i64 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %90
%94 = load i32, i32* @stderr
%95 = load i8*, i8** %1
%96 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0), i8* %95)
%97 = call i32 @exit(i32 1)
unreachable
98: ; preds = %90
%99 = load i32, i32* %3
%100 = call i32 @df_convert_uint32(i32 %99)
%101 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %100)
%102 = call i64 (i32, ...) @read(i32 %83, i32* %7, i64 4)
%103 = icmp slt i64 %102, 0
br i1 %103, label %104, label %109
104: ; preds = %98
%105 = load i32, i32* @stderr
%106 = load i8*, i8** %1
%107 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %105, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.14, i64 0, i64 0), i8* %106)
%108 = call i32 @exit(i32 1)
unreachable
109: ; preds = %98
%110 = load i32, i32* %7
%111 = call i32 @df_convert_uint32(i32 %110)
%112 = load i32, i32* %7
%113 = call i32 @df_convert_uint32(i32 %112)
%114 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.15, i64 0, i64 0), i32 %111, i32 %113)
%115 = load i32, i32* %4
%116 = icmp sgt i32 %115, 0
br i1 %116, label %117, label %134
117: ; preds = %109, %126
%118 = phi i32 [ %131, %126 ], [ 0, %109 ]
%119 = call i64 (i32, ...) @read(i32 %14, i8* %74, i32 %72)
%120 = icmp slt i64 %119, 1
br i1 %120, label %121, label %126
121: ; preds = %117
%122 = load i32, i32* @stderr
%123 = load i8*, i8** %1
%124 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0), i8* %123)
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %117
%127 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.17, i64 0, i64 0), i32 %118, i32 %72)
%128 = load i32, i32* %5
%129 = load i32, i32* %6
%130 = call i32 @disp_image(i8* %74, i32 %128, i32 %129)
%131 = add nuw nsw i32 %118, 1
%132 = load i32, i32* %4
%133 = icmp slt i32 %131, %132
br i1 %133, label %117, label %134
134: ; preds = %126, %109
%135 = call i32 @close(i32 %83)
%136 = call i32 @close(i32 %14)
ret i32 0
}