#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ setMessageToDisplayEx(unsigned char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ writeCG(int /*<<< orphan*/, unsigned char *);
void printBitmap(char *filename, int animationTime) {
  FILE *fd;
  int i, x;
  unsigned char *buf;
  unsigned char *tx;
  buf = malloc(35);
  tx = malloc(17);
  if (fd = fopen(filename, "r")) {
    fread(buf, 35, 1, fd);
    x = 0;
    for (i = 0; i < 35; i += 5) {
      writeCG(x++, &buf[i]);
    }
    while (fread(tx, 17, 1, fd) > 0) {
      setMessageToDisplayEx(tx, 16);
      usleep(animationTime);
    }
    fclose(fd);
  } else {
    fprintf(stderr, "cannot open file\n");
  }
  free(tx);
  free(buf);
}


x86 assembly (clang, -O0):
<printBitmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x23,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1280 <printBitmap+0xf0>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x23,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x23,-0x1c(%rbp)
jge    1231 <printBitmap+0xa1>
mov    -0x20(%rbp),%edi
mov    %edi,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1090 <writeCG@plt>
mov    -0x1c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x1c(%rbp)
jmp    11fe <printBitmap+0x6e>
jmp    1236 <printBitmap+0xa6>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x11,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x0,%rax
jle    1272 <printBitmap+0xe2>
mov    -0x30(%rbp),%rdi
mov    $0x10,%esi
call   1050 <setMessageToDisplayEx@plt>
mov    -0xc(%rbp),%edi
call   10b0 <usleep@plt>
jmp    1236 <printBitmap+0xa6>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
jmp    1295 <printBitmap+0x105>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd72(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printBitmap>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbp
mov    $0x23,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe42(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128b <printBitmap+0xfb>
mov    %rax,%rbp
mov    %r14,%rdi
mov    $0x23,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1090 <writeCG@plt>
lea    0x5(%r14),%rsi
mov    $0x1,%edi
call   1090 <writeCG@plt>
lea    0xa(%r14),%rsi
mov    $0x2,%edi
call   1090 <writeCG@plt>
lea    0xf(%r14),%rsi
mov    $0x3,%edi
call   1090 <writeCG@plt>
lea    0x14(%r14),%rsi
mov    $0x4,%edi
call   1090 <writeCG@plt>
lea    0x19(%r14),%rsi
mov    $0x5,%edi
call   1090 <writeCG@plt>
mov    %r14,%rsi
add    $0x1e,%rsi
mov    $0x6,%edi
call   1090 <writeCG@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x11,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    1281 <printBitmap+0xf1>
mov    %rbx,%rdi
mov    $0x10,%esi
call   1050 <setMessageToDisplayEx@plt>
mov    %r15d,%edi
call   10b0 <usleep@plt>
jmp    1250 <printBitmap+0xc0>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    12a0 <printBitmap+0x110>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"cannot open file\0A\00"
define void @printBitmap(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%10 = call i8* @malloc(i32 35)
store i8* %10, i8** %8
%11 = call i8* @malloc(i32 17)
store i8* %11, i8** %9
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %47
15: ; preds = %2
%16 = load i8*, i8** %8
%17 = load i32*, i32** %5
%18 = call i64 @fread(i8* %16, i32 35, i32 1, i32* %17)
store i32 0, i32* %7
store i32 0, i32* %6
br label %19
19: ; preds = %30, %15
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 35
br i1 %21, label %22, label %33
22: ; preds = %19
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = load i8*, i8** %8
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = call i32 @writeCG(i32 %23, i8* %28)
br label %30
30: ; preds = %22
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 5
store i32 %32, i32* %6
br label %19
33: ; preds = %19
br label %34
34: ; preds = %39, %33
%35 = load i8*, i8** %9
%36 = load i32*, i32** %5
%37 = call i64 @fread(i8* %35, i32 17, i32 1, i32* %36)
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i8*, i8** %9
%41 = call i32 @setMessageToDisplayEx(i8* %40, i32 16)
%42 = load i32, i32* %4
%43 = call i32 @usleep(i32 %42)
br label %34
44: ; preds = %34
%45 = load i32*, i32** %5
%46 = call i32 @fclose(i32* %45)
br label %50
47: ; preds = %2
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %50
50: ; preds = %47, %44
%51 = load i8*, i8** %9
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"cannot open file\0A\00"
define void @printBitmap(i8* nocapture %0, i32 %1) {
%3 = tail call dereferenceable_or_null(35) i8* @malloc(i32 35)
%4 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %31, label %7
7: ; preds = %2
%8 = tail call i64 @fread(i8* %3, i32 35, i32 1, i32* %5)
%9 = tail call i32 @writeCG(i32 0, i8* %3)
%10 = getelementptr inbounds i8, i8* %3, i64 5
%11 = tail call i32 @writeCG(i32 1, i8* %10)
%12 = getelementptr inbounds i8, i8* %3, i64 10
%13 = tail call i32 @writeCG(i32 2, i8* %12)
%14 = getelementptr inbounds i8, i8* %3, i64 15
%15 = tail call i32 @writeCG(i32 3, i8* %14)
%16 = getelementptr inbounds i8, i8* %3, i64 20
%17 = tail call i32 @writeCG(i32 4, i8* %16)
%18 = getelementptr inbounds i8, i8* %3, i64 25
%19 = tail call i32 @writeCG(i32 5, i8* %18)
%20 = getelementptr inbounds i8, i8* %3, i64 30
%21 = tail call i32 @writeCG(i32 6, i8* %20)
%22 = tail call i64 @fread(i8* %4, i32 17, i32 1, i32* %5)
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %7, %24
%25 = tail call i32 @setMessageToDisplayEx(i8* %4, i32 16)
%26 = tail call i32 @usleep(i32 %1)
%27 = tail call i64 @fread(i8* %4, i32 17, i32 1, i32* %5)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %24, label %29
29: ; preds = %24, %7
%30 = tail call i32 @fclose(i32* %5)
br label %34
31: ; preds = %2
%32 = load i32, i32* @stderr
%33 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %29
%35 = tail call i32 @free(i8* %4)
%36 = tail call i32 @free(i8* %3)
ret void
}