#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*/ s;
typedef int /*<<< orphan*/ head;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
unsigned int fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(unsigned int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char const *);
int sscanf(char *, char *, unsigned int *, unsigned int *, unsigned int *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void fb_drawimage(const char *filename, char *fbp, int xo, int yo, int bpp,
                  int length, int xres) {
  char head[256];
  char s[80];
  FILE *theme_file;
  unsigned char *pixline;
  unsigned i, j, width, height, line_size;
  memset(head, 0, sizeof(head));
  theme_file = fopen(filename, "r");
  while (1) {
    if (fgets(s, sizeof(s), theme_file) == NULL) {
      printf("bad PPM file '%s'", filename);
      exit(1);
    }
    if (s[0] == '#')
      continue;
    if (strlen(head) + strlen(s) >= sizeof(head)) {
      printf("bad PPM file '%s'", filename);
      exit(1);
    }
    strcat(head, s);
    if (head[0] != 'P' || head[1] != '6') {
      printf("bad PPM file '%s'", filename);
      exit(1);
    }
    if (sscanf(head, "P6 %u %u %u", &width, &height, &i) == 3)
      break;
  }
  line_size = width * 3;
  long int location = 0;
  pixline = malloc(line_size);
  for (j = 0; j < height; j++) {
    unsigned char *pixel = pixline;
    if (fread(pixline, 1, line_size, theme_file) != line_size) {
      printf("bad PPM file '%s'", filename);
      exit(1);
    }
    for (i = 0; i < width; i++) {
      pixel += 3;
      location = ((xres - width) + i + xo) * (bpp / 8) + (j + yo) * length;
      *(fbp + location) = (((unsigned)pixel[0]));
      *(fbp + location + 1) = (((unsigned)pixel[1]));
      *(fbp + location + 2) = (((unsigned)pixel[2]));
      *(fbp + location + 3) = -1;
    }
  }
  free(pixline);
  fclose(theme_file);
}


x86 assembly (clang, -O0):
<fb_drawimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x178(%rbp)
lea    -0x170(%rbp),%rdi
mov    -0x178(%rbp),%rdx
mov    $0x50,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    124a <fb_drawimage+0x8a>
mov    -0x8(%rbp),%rsi
lea    0xdc7(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movsbl -0x170(%rbp),%eax
cmp    $0x23,%eax
jne    125f <fb_drawimage+0x9f>
jmp    120e <fb_drawimage+0x4e>
lea    -0x120(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1ac(%rbp)
lea    -0x170(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x1ac(%rbp),%eax
add    %ecx,%eax
cltq
cmp    $0x100,%rax
jb     12af <fb_drawimage+0xef>
mov    -0x8(%rbp),%rsi
lea    0xd62(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x120(%rbp),%rdi
lea    -0x170(%rbp),%rsi
call   10d0 <strcat@plt>
movsbl -0x120(%rbp),%eax
cmp    $0x50,%eax
jne    12e2 <fb_drawimage+0x122>
movsbl -0x11f(%rbp),%eax
cmp    $0x36,%eax
je     12fc <fb_drawimage+0x13c>
mov    -0x8(%rbp),%rsi
lea    0xd15(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x120(%rbp),%rdi
lea    0xd0a(%rip),%rsi
lea    -0x18c(%rbp),%rdx
lea    -0x190(%rbp),%rcx
lea    -0x184(%rbp),%r8
call   10b0 <sscanf@plt>
cmp    $0x3,%eax
jne    1332 <fb_drawimage+0x172>
jmp    1337 <fb_drawimage+0x177>
jmp    120e <fb_drawimage+0x4e>
imul   $0x3,-0x18c(%rbp),%eax
mov    %eax,-0x194(%rbp)
movq   $0x0,-0x1a0(%rbp)
mov    -0x194(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x180(%rbp)
movl   $0x0,-0x188(%rbp)
mov    -0x188(%rbp),%eax
cmp    -0x190(%rbp),%eax
jae    14d2 <fb_drawimage+0x312>
mov    -0x180(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    -0x180(%rbp),%rdi
mov    -0x194(%rbp),%edx
mov    -0x178(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x194(%rbp),%eax
je     13cf <fb_drawimage+0x20f>
mov    -0x8(%rbp),%rsi
lea    0xc42(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movl   $0x0,-0x184(%rbp)
mov    -0x184(%rbp),%eax
cmp    -0x18c(%rbp),%eax
jae    14b9 <fb_drawimage+0x2f9>
mov    -0x1a8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x1a8(%rbp)
mov    0x10(%rbp),%eax
sub    -0x18c(%rbp),%eax
add    -0x184(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x1b0(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x1b0(%rbp),%eax
imul   %ecx,%eax
mov    -0x188(%rbp),%ecx
add    -0x18(%rbp),%ecx
imul   -0x20(%rbp),%ecx
add    %ecx,%eax
mov    %eax,%eax
mov    %rax,-0x1a0(%rbp)
mov    -0x1a8(%rbp),%rax
movzbl (%rax),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1a0(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1a8(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1a0(%rbp),%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x1a8(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x1a0(%rbp),%rcx
mov    %dl,0x2(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x1a0(%rbp),%rcx
movb   $0xff,0x3(%rax,%rcx,1)
mov    -0x184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x184(%rbp)
jmp    13d9 <fb_drawimage+0x219>
jmp    14be <fb_drawimage+0x2fe>
mov    -0x188(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x188(%rbp)
jmp    136b <fb_drawimage+0x1ab>
mov    -0x180(%rbp),%rdi
call   1030 <free@plt>
mov    -0x178(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_drawimage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8,0x30(%rsp)
mov    %rcx,0x40(%rsp)
mov    %rdx,0x20(%rsp)
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xa0(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    0xdfa(%rip),%rsi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     14a9 <fb_drawimage+0x2e9>
lea    0x50(%rsp),%rbp
lea    0xa0(%rsp),%r14
lea    0x3c(%rsp),%r12
jmp    1269 <fb_drawimage+0xa9>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     14a9 <fb_drawimage+0x2e9>
cmpb   $0x23,0x50(%rsp)
je     1250 <fb_drawimage+0x90>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r13d
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    %r13d,%eax
cmp    $0x100,%eax
jae    14a9 <fb_drawimage+0x2e9>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10d0 <strcat@plt>
cmpb   $0x50,0xa0(%rsp)
50
jne    14a9 <fb_drawimage+0x2e9>
cmpb   $0x36,0xa1(%rsp)
36
jne    14a9 <fb_drawimage+0x2e9>
mov    %r14,%rdi
lea    0xd52(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    %r12,%r8
call   10b0 <sscanf@plt>
cmp    $0x3,%eax
jne    1250 <fb_drawimage+0x90>
mov    %rbx,0x48(%rsp)
mov    0x14(%rsp),%eax
lea    (%rax,%rax,2),%edi
mov    %edi,0x38(%rsp)
call   10a0 <malloc@plt>
mov    %rax,0x28(%rsp)
cmpl   $0x0,0x10(%rsp)
mov    0xc(%rsp),%ebx
je     1483 <fb_drawimage+0x2c3>
mov    0x20(%rsp),%rcx
mov    0x1e0(%rsp),%eax
mov    %rax,%rsi
add    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    0x30(%rsp),%rdx
lea    0x7(%rdx),%eax
test   %edx,%edx
cmovns %edx,%eax
sar    $0x3,%eax
mov    %ebx,%r12d
imul   0x40(%rsp),%r12d
add    %esi,%ecx
add    $0x1,%ecx
mov    %ecx,0x30(%rsp)
mov    %rax,0x20(%rsp)
lea    (%rax,%rax,1),%r13d
xor    %r14d,%r14d
jmp    1367 <fb_drawimage+0x1a7>
nopl   0x0(%rax,%rax,1)
mov    %r8d,0x3c(%rsp)
add    $0x1,%r14d
add    %ebx,%r12d
cmp    0x10(%rsp),%r14d
jae    1483 <fb_drawimage+0x2c3>
mov    0x28(%rsp),%rdi
mov    $0x1,%esi
mov    0x38(%rsp),%ebp
mov    %ebp,%edx
mov    0x48(%rsp),%rcx
call   1040 <fread@plt>
cmp    %ebp,%eax
jne    14a9 <fb_drawimage+0x2e9>
mov    0x14(%rsp),%r8d
test   %r8,%r8
je     1350 <fb_drawimage+0x190>
cmp    $0x1,%r8d
jne    13b0 <fb_drawimage+0x1f0>
xor    %ecx,%ecx
mov    0x28(%rsp),%rbp
jmp    143a <fb_drawimage+0x27a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    0x30(%rsp),%esi
sub    %r8d,%esi
mov    0x20(%rsp),%rcx
imul   %ecx,%esi
add    %r12d,%esi
mov    0x8(%rsp),%eax
sub    %r8d,%eax
imul   %ecx,%eax
add    %r12d,%eax
xor    %ecx,%ecx
mov    0x28(%rsp),%rdi
nopl   (%rax)
mov    %eax,%ebp
movzbl 0x3(%rdi),%edx
mov    %dl,(%r15,%rbp,1)
movzbl 0x4(%rdi),%edx
mov    %dl,0x1(%r15,%rbp,1)
movzbl 0x5(%rdi),%edx
mov    %dl,0x2(%r15,%rbp,1)
movb   $0xff,0x3(%r15,%rbp,1)
lea    0x6(%rdi),%rbp
mov    %esi,%edx
movzbl 0x6(%rdi),%ebx
mov    %bl,(%r15,%rdx,1)
movzbl 0x7(%rdi),%ebx
mov    %bl,0x1(%r15,%rdx,1)
movzbl 0x8(%rdi),%ebx
mov    %bl,0x2(%r15,%rdx,1)
movb   $0xff,0x3(%r15,%rdx,1)
add    $0x2,%rcx
add    %r13d,%esi
add    %r13d,%eax
mov    %rbp,%rdi
cmp    %rcx,%r9
jne    13e0 <fb_drawimage+0x220>
test   $0x1,%r8b
mov    0xc(%rsp),%ebx
je     1350 <fb_drawimage+0x190>
mov    0x40(%rsp),%rax
add    %r14d,%eax
imul   %ebx,%eax
add    0x8(%rsp),%ecx
sub    %r8d,%ecx
imul   0x20(%rsp),%ecx
add    %eax,%ecx
mov    0x3(%rbp),%al
mov    %al,(%r15,%rcx,1)
mov    0x4(%rbp),%al
mov    %al,0x1(%r15,%rcx,1)
mov    0x5(%rbp),%al
mov    %al,0x2(%r15,%rcx,1)
movb   $0xff,0x3(%r15,%rcx,1)
jmp    1350 <fb_drawimage+0x190>
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    0x48(%rsp),%rdi
call   1050 <fclose@plt>
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb52(%rip),%rdi
mov    0x18(%rsp),%rsi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"bad PPM file '%s'\00"
@.str.2 = [12 x i8] c"P6 %u %u %u\00"
define void @fb_drawimage(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [256 x i8]
%16 = alloca [80 x i8]
%17 = alloca i32*
%18 = alloca i8*
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i64
%25 = alloca i8*
store i8* %0, i8** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%27 = call i32 @memset(i8* %26, i32 0, i32 256)
%28 = load i8*, i8** %8
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %17
br label %30
30: ; preds = %7, %44, %79
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %16, i64 0, i64 0
%32 = load i32*, i32** %17
%33 = call i32* @fgets(i8* %31, i32 80, i32* %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i8*, i8** %8
%37 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %16, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 35
br i1 %43, label %44, label %45
44: ; preds = %39
br label %30
45: ; preds = %39
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %16, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = add nsw i32 %47, %49
%51 = sext i32 %50 to i64
%52 = icmp uge i64 %51, 256
br i1 %52, label %53, label %57
53: ; preds = %45
%54 = load i8*, i8** %8
%55 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %54)
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %45
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%59 = getelementptr inbounds [80 x i8], [80 x i8]* %16, i64 0, i64 0
%60 = call i32 @strcat(i8* %58, i8* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp ne i32 %63, 80
br i1 %64, label %70, label %65
65: ; preds = %57
%66 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 1
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 54
br i1 %69, label %70, label %74
70: ; preds = %65, %57
%71 = load i8*, i8** %8
%72 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %71)
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %65
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%76 = call i32 @sscanf(i8* %75, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %21, i32* %22, i32* %19)
%77 = icmp eq i32 %76, 3
br i1 %77, label %78, label %79
78: ; preds = %74
br label %80
79: ; preds = %74
br label %30
80: ; preds = %78
%81 = load i32, i32* %21
%82 = mul i32 %81, 3
store i32 %82, i32* %23
store i64 0, i64* %24
%83 = load i32, i32* %23
%84 = call i8* @malloc(i32 %83)
store i8* %84, i8** %18
store i32 0, i32* %20
br label %85
85: ; preds = %160, %80
%86 = load i32, i32* %20
%87 = load i32, i32* %22
%88 = icmp ult i32 %86, %87
br i1 %88, label %89, label %163
89: ; preds = %85
%90 = load i8*, i8** %18
store i8* %90, i8** %25
%91 = load i8*, i8** %18
%92 = load i32, i32* %23
%93 = load i32*, i32** %17
%94 = call i32 @fread(i8* %91, i32 1, i32 %92, i32* %93)
%95 = load i32, i32* %23
%96 = icmp ne i32 %94, %95
br i1 %96, label %97, label %101
97: ; preds = %89
%98 = load i8*, i8** %8
%99 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %98)
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %89
store i32 0, i32* %19
br label %102
102: ; preds = %156, %101
%103 = load i32, i32* %19
%104 = load i32, i32* %21
%105 = icmp ult i32 %103, %104
br i1 %105, label %106, label %159
106: ; preds = %102
%107 = load i8*, i8** %25
%108 = getelementptr inbounds i8, i8* %107, i64 3
store i8* %108, i8** %25
%109 = load i32, i32* %14
%110 = load i32, i32* %21
%111 = sub i32 %109, %110
%112 = load i32, i32* %19
%113 = add i32 %111, %112
%114 = load i32, i32* %10
%115 = add i32 %113, %114
%116 = load i32, i32* %12
%117 = sdiv i32 %116, 8
%118 = mul i32 %115, %117
%119 = load i32, i32* %20
%120 = load i32, i32* %11
%121 = add i32 %119, %120
%122 = load i32, i32* %13
%123 = mul i32 %121, %122
%124 = add i32 %118, %123
%125 = zext i32 %124 to i64
store i64 %125, i64* %24
%126 = load i8*, i8** %25
%127 = getelementptr inbounds i8, i8* %126, i64 0
%128 = load i8, i8* %127
%129 = zext i8 %128 to i32
%130 = trunc i32 %129 to i8
%131 = load i8*, i8** %9
%132 = load i64, i64* %24
%133 = getelementptr inbounds i8, i8* %131, i64 %132
store i8 %130, i8* %133
%134 = load i8*, i8** %25
%135 = getelementptr inbounds i8, i8* %134, i64 1
%136 = load i8, i8* %135
%137 = zext i8 %136 to i32
%138 = trunc i32 %137 to i8
%139 = load i8*, i8** %9
%140 = load i64, i64* %24
%141 = getelementptr inbounds i8, i8* %139, i64 %140
%142 = getelementptr inbounds i8, i8* %141, i64 1
store i8 %138, i8* %142
%143 = load i8*, i8** %25
%144 = getelementptr inbounds i8, i8* %143, i64 2
%145 = load i8, i8* %144
%146 = zext i8 %145 to i32
%147 = trunc i32 %146 to i8
%148 = load i8*, i8** %9
%149 = load i64, i64* %24
%150 = getelementptr inbounds i8, i8* %148, i64 %149
%151 = getelementptr inbounds i8, i8* %150, i64 2
store i8 %147, i8* %151
%152 = load i8*, i8** %9
%153 = load i64, i64* %24
%154 = getelementptr inbounds i8, i8* %152, i64 %153
%155 = getelementptr inbounds i8, i8* %154, i64 3
store i8 -1, i8* %155
br label %156
156: ; preds = %106
%157 = load i32, i32* %19
%158 = add i32 %157, 1
store i32 %158, i32* %19
br label %102
159: ; preds = %102
br label %160
160: ; preds = %159
%161 = load i32, i32* %20
%162 = add i32 %161, 1
store i32 %162, i32* %20
br label %85
163: ; preds = %85
%164 = load i8*, i8** %18
%165 = call i32 @free(i8* %164)
%166 = load i32*, i32** %17
%167 = call i32 @fclose(i32* %166)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"bad PPM file '%s'\00"
@.str.2 = [12 x i8] c"P6 %u %u %u\00"
define void @fb_drawimage(i8* %0, i8* nocapture writeonly %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca [256 x i8]
%9 = alloca [80 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%15 = bitcast i32* %10 to i8*
%16 = bitcast i32* %11 to i8*
%17 = bitcast i32* %12 to i8*
%18 = call i32 @memset(i8* %13, i32 0, i32 256)
%19 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = call i32* @fgets(i8* %14, i32 80, i32* %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %7
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 1
br label %27
24: ; preds = %30, %7
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %22, %30
%28 = load i8, i8* %14
%29 = icmp eq i8 %28, 35
br i1 %29, label %30, label %33
30: ; preds = %27, %51
%31 = call i32* @fgets(i8* %14, i32 80, i32* %19)
%32 = icmp eq i32* %31, null
br i1 %32, label %24, label %27
33: ; preds = %27
%34 = call i32 @strlen(i8* %13)
%35 = call i32 @strlen(i8* %14)
%36 = add nsw i32 %35, %34
%37 = icmp ugt i32 %36, 255
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
%42 = call i32 @strcat(i8* %13, i8* %14)
%43 = load i8, i8* %13
%44 = icmp ne i8 %43, 80
%45 = load i8, i8* %23
%46 = icmp ne i8 %45, 54
%47 = select i1 %44, i1 true, i1 %46
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %11, i32* %12, i32* %10)
%53 = icmp eq i32 %52, 3
br i1 %53, label %54, label %30
54: ; preds = %51
%55 = load i32, i32* %11
%56 = mul i32 %55, 3
%57 = call i8* @malloc(i32 %56)
%58 = load i32, i32* %12
%59 = icmp eq i32 %58, 0
br i1 %59, label %146, label %60
60: ; preds = %54
%61 = add i32 %6, %2
%62 = sdiv i32 %4, 8
br label %63
63: ; preds = %60, %142
%64 = phi i32 [ 0, %60 ], [ %143, %142 ]
%65 = call i32 @fread(i8* %57, i32 1, i32 %56, i32* %19)
%66 = icmp eq i32 %65, %56
br i1 %66, label %67, label %78
67: ; preds = %63
%68 = load i32, i32* %11
%69 = icmp eq i32 %68, 0
br i1 %69, label %142, label %70
70: ; preds = %67
%71 = add i32 %64, %3
%72 = mul i32 %71, %5
%73 = zext i32 %68 to i64
%74 = and i64 %73, 1
%75 = icmp eq i32 %68, 1
br i1 %75, label %121, label %76
76: ; preds = %70
%77 = and i64 %73, 4294967294
br label %81
78: ; preds = %63
%79 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %81, %76
%82 = phi i64 [ 0, %76 ], [ %118, %81 ]
%83 = phi i8* [ %57, %76 ], [ %101, %81 ]
%84 = phi i64 [ 0, %76 ], [ %119, %81 ]
%85 = getelementptr inbounds i8, i8* %83, i64 3
%86 = trunc i64 %82 to i32
%87 = add i32 %61, %86
%88 = sub i32 %87, %68
%89 = mul i32 %88, %62
%90 = add i32 %89, %72
%91 = zext i32 %90 to i64
%92 = load i8, i8* %85
%93 = getelementptr inbounds i8, i8* %1, i64 %91
store i8 %92, i8* %93
%94 = getelementptr inbounds i8, i8* %83, i64 4
%95 = load i8, i8* %94
%96 = getelementptr inbounds i8, i8* %93, i64 1
store i8 %95, i8* %96
%97 = getelementptr inbounds i8, i8* %83, i64 5
%98 = load i8, i8* %97
%99 = getelementptr inbounds i8, i8* %93, i64 2
store i8 %98, i8* %99
%100 = getelementptr inbounds i8, i8* %93, i64 3
store i8 -1, i8* %100
%101 = getelementptr inbounds i8, i8* %83, i64 6
%102 = trunc i64 %82 to i32
%103 = or i32 %102, 1
%104 = add i32 %61, %103
%105 = sub i32 %104, %68
%106 = mul i32 %105, %62
%107 = add i32 %106, %72
%108 = zext i32 %107 to i64
%109 = load i8, i8* %101
%110 = getelementptr inbounds i8, i8* %1, i64 %108
store i8 %109, i8* %110
%111 = getelementptr inbounds i8, i8* %83, i64 7
%112 = load i8, i8* %111
%113 = getelementptr inbounds i8, i8* %110, i64 1
store i8 %112, i8* %113
%114 = getelementptr inbounds i8, i8* %83, i64 8
%115 = load i8, i8* %114
%116 = getelementptr inbounds i8, i8* %110, i64 2
store i8 %115, i8* %116
%117 = getelementptr inbounds i8, i8* %110, i64 3
store i8 -1, i8* %117
%118 = add nuw nsw i64 %82, 2
%119 = add i64 %84, 2
%120 = icmp eq i64 %119, %77
br i1 %120, label %121, label %81
121: ; preds = %81, %70
%122 = phi i64 [ 0, %70 ], [ %118, %81 ]
%123 = phi i8* [ %57, %70 ], [ %101, %81 ]
%124 = icmp eq i64 %74, 0
br i1 %124, label %142, label %125
125: ; preds = %121
%126 = getelementptr inbounds i8, i8* %123, i64 3
%127 = trunc i64 %122 to i32
%128 = add i32 %61, %127
%129 = sub i32 %128, %68
%130 = mul i32 %129, %62
%131 = add i32 %130, %72
%132 = zext i32 %131 to i64
%133 = load i8, i8* %126
%134 = getelementptr inbounds i8, i8* %1, i64 %132
store i8 %133, i8* %134
%135 = getelementptr inbounds i8, i8* %123, i64 4
%136 = load i8, i8* %135
%137 = getelementptr inbounds i8, i8* %134, i64 1
store i8 %136, i8* %137
%138 = getelementptr inbounds i8, i8* %123, i64 5
%139 = load i8, i8* %138
%140 = getelementptr inbounds i8, i8* %134, i64 2
store i8 %139, i8* %140
%141 = getelementptr inbounds i8, i8* %134, i64 3
store i8 -1, i8* %141
br label %142
142: ; preds = %125, %121, %67
store i32 %68, i32* %10
%143 = add nuw i32 %64, 1
%144 = load i32, i32* %12
%145 = icmp ult i32 %143, %144
br i1 %145, label %63, label %146
146: ; preds = %142, %54
%147 = call i32 @free(i8* %57)
%148 = call i32 @fclose(i32* %19)
ret void
}