#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) {
  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 = (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) = 2;
    }
  }
  free(pixline);
  fclose(theme_file);
}


x86 assembly (clang, -O0):
<fb_drawimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
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    0xe01(%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    1247 <fb_drawimage+0x87>
mov    -0x8(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
movsbl -0x170(%rbp),%eax
cmp    $0x23,%eax
jne    125c <fb_drawimage+0x9c>
jmp    120b <fb_drawimage+0x4b>
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     12ac <fb_drawimage+0xec>
mov    -0x8(%rbp),%rsi
lea    0xd65(%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    12df <fb_drawimage+0x11f>
movsbl -0x11f(%rbp),%eax
cmp    $0x36,%eax
je     12f9 <fb_drawimage+0x139>
mov    -0x8(%rbp),%rsi
lea    0xd18(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x120(%rbp),%rdi
lea    0xd0d(%rip),%rsi
lea    -0x18c(%rbp),%rdx
lea    -0x190(%rbp),%rcx
lea    -0x184(%rbp),%r8
call   10b0 <sscanf@plt>
cmp    $0x3,%eax
jne    132f <fb_drawimage+0x16f>
jmp    1334 <fb_drawimage+0x174>
jmp    120b <fb_drawimage+0x4b>
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    14c6 <fb_drawimage+0x306>
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     13cc <fb_drawimage+0x20c>
mov    -0x8(%rbp),%rsi
lea    0xc45(%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    14ad <fb_drawimage+0x2ed>
mov    -0x1a8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x1a8(%rbp)
mov    -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   $0x2,0x3(%rax,%rcx,1)
mov    -0x184(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x184(%rbp)
jmp    13d6 <fb_drawimage+0x216>
jmp    14b2 <fb_drawimage+0x2f2>
mov    -0x188(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x188(%rbp)
jmp    1368 <fb_drawimage+0x1a8>
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,0x4(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,0x38(%rsp)
mov    %rdx,0x30(%rsp)
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xa0(%rsp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
lea    0xdfa(%rip),%rsi
mov    %rbx,0x10(%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     14a8 <fb_drawimage+0x2e8>
lea    0x50(%rsp),%rbp
lea    0xa0(%rsp),%r14
lea    0x2c(%rsp),%r13
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     14a8 <fb_drawimage+0x2e8>
cmpb   $0x23,0x50(%rsp)
je     1250 <fb_drawimage+0x90>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1060 <strlen@plt>
add    %r15d,%eax
cmp    $0x100,%eax
jae    14a8 <fb_drawimage+0x2e8>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10d0 <strcat@plt>
cmpb   $0x50,0xa0(%rsp)
50
jne    14a8 <fb_drawimage+0x2e8>
cmpb   $0x36,0xa1(%rsp)
36
jne    14a8 <fb_drawimage+0x2e8>
mov    %r14,%rdi
lea    0xd52(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %r13,%r8
call   10b0 <sscanf@plt>
cmp    $0x3,%eax
jne    1250 <fb_drawimage+0x90>
mov    %rbx,0x40(%rsp)
mov    0xc(%rsp),%eax
lea    (%rax,%rax,2),%edi
mov    %edi,0x28(%rsp)
call   10a0 <malloc@plt>
mov    %rax,0x18(%rsp)
cmpl   $0x0,0x8(%rsp)
mov    0x4(%rsp),%r15d
je     1482 <fb_drawimage+0x2c2>
mov    0x20(%rsp),%rax
lea    0x7(%rax),%edx
test   %eax,%eax
cmovns %eax,%edx
sar    $0x3,%edx
mov    %r15d,%eax
imul   0x38(%rsp),%eax
mov    0x30(%rsp),%rcx
lea    0x1(%rcx),%r10d
imul   %edx,%r10d
add    %eax,%r10d
lea    (%rdx,%rdx,1),%r13d
mov    %rdx,0x48(%rsp)
mov    %edx,%r11d
imul   %ecx,%r11d
add    %eax,%r11d
xor    %r14d,%r14d
jmp    136a <fb_drawimage+0x1aa>
nopw   0x0(%rax,%rax,1)
mov    %r8d,0x2c(%rsp)
add    $0x1,%r14d
add    %r15d,%r10d
add    %r15d,%r11d
cmp    0x8(%rsp),%r14d
jae    1482 <fb_drawimage+0x2c2>
mov    %r14,0x20(%rsp)
mov    %r11d,%r14d
mov    %r10d,%ebx
mov    0x18(%rsp),%rdi
mov    $0x1,%esi
mov    0x28(%rsp),%ebp
mov    %ebp,%edx
mov    0x40(%rsp),%rcx
call   1040 <fread@plt>
cmp    %ebp,%eax
jne    14a8 <fb_drawimage+0x2e8>
mov    0xc(%rsp),%r8d
test   %r8,%r8
mov    %ebx,%r10d
mov    %r14d,%r11d
mov    0x20(%rsp),%r14
je     1350 <fb_drawimage+0x190>
cmp    $0x1,%r8d
jne    13c0 <fb_drawimage+0x200>
xor    %ecx,%ecx
mov    0x18(%rsp),%rsi
jmp    143a <fb_drawimage+0x27a>
xchg   %ax,%ax
mov    %r8d,%r9d
and    $0xfffffffe,%r9d
mov    %r11d,%edi
mov    %r10d,%ebp
xor    %ecx,%ecx
mov    0x18(%rsp),%rdx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%eax
movzbl 0x3(%rdx),%ebx
mov    %bl,(%r12,%rax,1)
movzbl 0x4(%rdx),%ebx
mov    %bl,0x1(%r12,%rax,1)
movzbl 0x5(%rdx),%ebx
mov    %bl,0x2(%r12,%rax,1)
movb   $0x2,0x3(%r12,%rax,1)
lea    0x6(%rdx),%rsi
mov    %ebp,%ebx
movzbl 0x6(%rdx),%eax
mov    %al,(%r12,%rbx,1)
movzbl 0x7(%rdx),%eax
mov    %al,0x1(%r12,%rbx,1)
movzbl 0x8(%rdx),%eax
mov    %al,0x2(%r12,%rbx,1)
movb   $0x2,0x3(%r12,%rbx,1)
add    $0x2,%rcx
add    %r13d,%ebp
add    %r13d,%edi
mov    %rsi,%rdx
cmp    %rcx,%r9
jne    13e0 <fb_drawimage+0x220>
test   $0x1,%r8b
mov    0x4(%rsp),%r15d
je     1350 <fb_drawimage+0x190>
mov    0x38(%rsp),%rax
add    %r14d,%eax
imul   %r15d,%eax
add    0x30(%rsp),%ecx
imul   0x48(%rsp),%ecx
add    %eax,%ecx
mov    0x3(%rsi),%al
mov    %al,(%r12,%rcx,1)
mov    0x4(%rsi),%al
mov    %al,0x1(%r12,%rcx,1)
mov    0x5(%rsi),%al
mov    %al,0x2(%r12,%rcx,1)
movb   $0x2,0x3(%r12,%rcx,1)
jmp    1350 <fb_drawimage+0x190>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x40(%rsp),%rdi
call   1050 <fclose@plt>
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb53(%rip),%rdi
mov    0x10(%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) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca [256 x i8]
%14 = alloca [80 x i8]
%15 = alloca i32*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i64
%23 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%25 = call i32 @memset(i8* %24, i32 0, i32 256)
%26 = load i8*, i8** %7
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %15
br label %28
28: ; preds = %6, %42, %77
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%30 = load i32*, i32** %15
%31 = call i32* @fgets(i8* %29, i32 80, i32* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 35
br i1 %41, label %42, label %43
42: ; preds = %37
br label %28
43: ; preds = %37
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%45 = call i32 @strlen(i8* %44)
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %45, %47
%49 = sext i32 %48 to i64
%50 = icmp uge i64 %49, 256
br i1 %50, label %51, label %55
51: ; preds = %43
%52 = load i8*, i8** %7
%53 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %52)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %43
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%57 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%58 = call i32 @strcat(i8* %56, i8* %57)
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 80
br i1 %62, label %68, label %63
63: ; preds = %55
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 1
%65 = load i8, i8* %64
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %66, 54
br i1 %67, label %68, label %72
68: ; preds = %63, %55
%69 = load i8*, i8** %7
%70 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %69)
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %63
%73 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%74 = call i32 @sscanf(i8* %73, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %19, i32* %20, i32* %17)
%75 = icmp eq i32 %74, 3
br i1 %75, label %76, label %77
76: ; preds = %72
br label %78
77: ; preds = %72
br label %28
78: ; preds = %76
%79 = load i32, i32* %19
%80 = mul i32 %79, 3
store i32 %80, i32* %21
store i64 0, i64* %22
%81 = load i32, i32* %21
%82 = call i8* @malloc(i32 %81)
store i8* %82, i8** %16
store i32 0, i32* %18
br label %83
83: ; preds = %154, %78
%84 = load i32, i32* %18
%85 = load i32, i32* %20
%86 = icmp ult i32 %84, %85
br i1 %86, label %87, label %157
87: ; preds = %83
%88 = load i8*, i8** %16
store i8* %88, i8** %23
%89 = load i8*, i8** %16
%90 = load i32, i32* %21
%91 = load i32*, i32** %15
%92 = call i32 @fread(i8* %89, i32 1, i32 %90, i32* %91)
%93 = load i32, i32* %21
%94 = icmp ne i32 %92, %93
br i1 %94, label %95, label %99
95: ; preds = %87
%96 = load i8*, i8** %7
%97 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %96)
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %87
store i32 0, i32* %17
br label %100
100: ; preds = %150, %99
%101 = load i32, i32* %17
%102 = load i32, i32* %19
%103 = icmp ult i32 %101, %102
br i1 %103, label %104, label %153
104: ; preds = %100
%105 = load i8*, i8** %23
%106 = getelementptr inbounds i8, i8* %105, i64 3
store i8* %106, i8** %23
%107 = load i32, i32* %17
%108 = load i32, i32* %9
%109 = add i32 %107, %108
%110 = load i32, i32* %11
%111 = sdiv i32 %110, 8
%112 = mul i32 %109, %111
%113 = load i32, i32* %18
%114 = load i32, i32* %10
%115 = add i32 %113, %114
%116 = load i32, i32* %12
%117 = mul i32 %115, %116
%118 = add i32 %112, %117
%119 = zext i32 %118 to i64
store i64 %119, i64* %22
%120 = load i8*, i8** %23
%121 = getelementptr inbounds i8, i8* %120, i64 0
%122 = load i8, i8* %121
%123 = zext i8 %122 to i32
%124 = trunc i32 %123 to i8
%125 = load i8*, i8** %8
%126 = load i64, i64* %22
%127 = getelementptr inbounds i8, i8* %125, i64 %126
store i8 %124, i8* %127
%128 = load i8*, i8** %23
%129 = getelementptr inbounds i8, i8* %128, i64 1
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = trunc i32 %131 to i8
%133 = load i8*, i8** %8
%134 = load i64, i64* %22
%135 = getelementptr inbounds i8, i8* %133, i64 %134
%136 = getelementptr inbounds i8, i8* %135, i64 1
store i8 %132, i8* %136
%137 = load i8*, i8** %23
%138 = getelementptr inbounds i8, i8* %137, i64 2
%139 = load i8, i8* %138
%140 = zext i8 %139 to i32
%141 = trunc i32 %140 to i8
%142 = load i8*, i8** %8
%143 = load i64, i64* %22
%144 = getelementptr inbounds i8, i8* %142, i64 %143
%145 = getelementptr inbounds i8, i8* %144, i64 2
store i8 %141, i8* %145
%146 = load i8*, i8** %8
%147 = load i64, i64* %22
%148 = getelementptr inbounds i8, i8* %146, i64 %147
%149 = getelementptr inbounds i8, i8* %148, i64 3
store i8 2, i8* %149
br label %150
150: ; preds = %104
%151 = load i32, i32* %17
%152 = add i32 %151, 1
store i32 %152, i32* %17
br label %100
153: ; preds = %100
br label %154
154: ; preds = %153
%155 = load i32, i32* %18
%156 = add i32 %155, 1
store i32 %156, i32* %18
br label %83
157: ; preds = %83
%158 = load i8*, i8** %16
%159 = call i32 @free(i8* %158)
%160 = load i32*, i32** %15
%161 = call i32 @fclose(i32* %160)
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) {
%7 = alloca [256 x i8]
%8 = alloca [80 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%14 = bitcast i32* %9 to i8*
%15 = bitcast i32* %10 to i8*
%16 = bitcast i32* %11 to i8*
%17 = call i32 @memset(i8* %12, i32 0, i32 256)
%18 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = call i32* @fgets(i8* %13, i32 80, i32* %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %6
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 1
br label %26
23: ; preds = %29, %6
%24 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %21, %29
%27 = load i8, i8* %13
%28 = icmp eq i8 %27, 35
br i1 %28, label %29, label %32
29: ; preds = %26, %50
%30 = call i32* @fgets(i8* %13, i32 80, i32* %18)
%31 = icmp eq i32* %30, null
br i1 %31, label %23, label %26
32: ; preds = %26
%33 = call i32 @strlen(i8* %12)
%34 = call i32 @strlen(i8* %13)
%35 = add nsw i32 %34, %33
%36 = icmp ugt i32 %35, 255
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32
%41 = call i32 @strcat(i8* %12, i8* %13)
%42 = load i8, i8* %12
%43 = icmp ne i8 %42, 80
%44 = load i8, i8* %22
%45 = icmp ne i8 %44, 54
%46 = select i1 %43, i1 true, i1 %45
br i1 %46, label %47, label %50
47: ; preds = %40
%48 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %40
%51 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32* %10, i32* %11, i32* %9)
%52 = icmp eq i32 %51, 3
br i1 %52, label %53, label %29
53: ; preds = %50
%54 = load i32, i32* %10
%55 = mul i32 %54, 3
%56 = call i8* @malloc(i32 %55)
%57 = load i32, i32* %11
%58 = icmp eq i32 %57, 0
br i1 %58, label %141, label %59
59: ; preds = %53
%60 = sdiv i32 %4, 8
br label %61
61: ; preds = %59, %137
%62 = phi i32 [ 0, %59 ], [ %138, %137 ]
%63 = call i32 @fread(i8* %56, i32 1, i32 %55, i32* %18)
%64 = icmp eq i32 %63, %55
br i1 %64, label %65, label %76
65: ; preds = %61
%66 = load i32, i32* %10
%67 = icmp eq i32 %66, 0
br i1 %67, label %137, label %68
68: ; preds = %65
%69 = add i32 %62, %3
%70 = mul i32 %69, %5
%71 = zext i32 %66 to i64
%72 = and i64 %71, 1
%73 = icmp eq i32 %66, 1
br i1 %73, label %117, label %74
74: ; preds = %68
%75 = and i64 %71, 4294967294
br label %79
76: ; preds = %61
%77 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %79, %74
%80 = phi i64 [ 0, %74 ], [ %114, %79 ]
%81 = phi i8* [ %56, %74 ], [ %98, %79 ]
%82 = phi i64 [ 0, %74 ], [ %115, %79 ]
%83 = getelementptr inbounds i8, i8* %81, i64 3
%84 = trunc i64 %80 to i32
%85 = add i32 %84, %2
%86 = mul i32 %85, %60
%87 = add i32 %86, %70
%88 = zext i32 %87 to i64
%89 = load i8, i8* %83
%90 = getelementptr inbounds i8, i8* %1, i64 %88
store i8 %89, i8* %90
%91 = getelementptr inbounds i8, i8* %81, i64 4
%92 = load i8, i8* %91
%93 = getelementptr inbounds i8, i8* %90, i64 1
store i8 %92, i8* %93
%94 = getelementptr inbounds i8, i8* %81, i64 5
%95 = load i8, i8* %94
%96 = getelementptr inbounds i8, i8* %90, i64 2
store i8 %95, i8* %96
%97 = getelementptr inbounds i8, i8* %90, i64 3
store i8 2, i8* %97
%98 = getelementptr inbounds i8, i8* %81, i64 6
%99 = trunc i64 %80 to i32
%100 = or i32 %99, 1
%101 = add i32 %100, %2
%102 = mul i32 %101, %60
%103 = add i32 %102, %70
%104 = zext i32 %103 to i64
%105 = load i8, i8* %98
%106 = getelementptr inbounds i8, i8* %1, i64 %104
store i8 %105, i8* %106
%107 = getelementptr inbounds i8, i8* %81, i64 7
%108 = load i8, i8* %107
%109 = getelementptr inbounds i8, i8* %106, i64 1
store i8 %108, i8* %109
%110 = getelementptr inbounds i8, i8* %81, i64 8
%111 = load i8, i8* %110
%112 = getelementptr inbounds i8, i8* %106, i64 2
store i8 %111, i8* %112
%113 = getelementptr inbounds i8, i8* %106, i64 3
store i8 2, i8* %113
%114 = add nuw nsw i64 %80, 2
%115 = add i64 %82, 2
%116 = icmp eq i64 %115, %75
br i1 %116, label %117, label %79
117: ; preds = %79, %68
%118 = phi i64 [ 0, %68 ], [ %114, %79 ]
%119 = phi i8* [ %56, %68 ], [ %98, %79 ]
%120 = icmp eq i64 %72, 0
br i1 %120, label %137, label %121
121: ; preds = %117
%122 = getelementptr inbounds i8, i8* %119, i64 3
%123 = trunc i64 %118 to i32
%124 = add i32 %123, %2
%125 = mul i32 %124, %60
%126 = add i32 %125, %70
%127 = zext i32 %126 to i64
%128 = load i8, i8* %122
%129 = getelementptr inbounds i8, i8* %1, i64 %127
store i8 %128, i8* %129
%130 = getelementptr inbounds i8, i8* %119, i64 4
%131 = load i8, i8* %130
%132 = getelementptr inbounds i8, i8* %129, i64 1
store i8 %131, i8* %132
%133 = getelementptr inbounds i8, i8* %119, i64 5
%134 = load i8, i8* %133
%135 = getelementptr inbounds i8, i8* %129, i64 2
store i8 %134, i8* %135
%136 = getelementptr inbounds i8, i8* %129, i64 3
store i8 2, i8* %136
br label %137
137: ; preds = %121, %117, %65
store i32 %66, i32* %9
%138 = add nuw i32 %62, 1
%139 = load i32, i32* %11
%140 = icmp ult i32 %138, %139
br i1 %140, label %61, label %141
141: ; preds = %137, %53
%142 = call i32 @free(i8* %56)
%143 = call i32 @fclose(i32* %18)
ret void
}