#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 */

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
unsigned char *image_rgb24_from_rgb96f(int, int, void *);
unsigned char *image_rgb48be_from_rgb96f(int, int, void *);
unsigned char *image_rgb48bepl_from_rgb96f(int, int, void *);
int /*<<< orphan*/ printf(char *);
int writebmp(char *, int, int, unsigned char *);
int writejpeg(char *, int, int, unsigned char *);
int writepng(char *, int, int, unsigned char *);
int writeppm(char *, int, int, unsigned char *);
int writeppm48(char *, int, int, unsigned char *);
int writepsd48(char *, int, int, unsigned char *);
int writergb(char *, int, int, unsigned char *);
int writetga(char *, int, int, unsigned char *);
int writeimage(char *name, int xres, int yres, void *img, int imgbufferformat,
               int fileformat) {
  if (img == NULL)
    return 6;
  if (imgbufferformat == 0) {
    unsigned char *imgbuf = (unsigned char *)img;
    switch (fileformat) {
    case 1:
      return writeppm(name, xres, yres, imgbuf);
    case 2:
      return writergb(name, xres, yres, imgbuf);
    case 3:
      return writejpeg(name, xres, yres, imgbuf);
    case 5:
      return writepng(name, xres, yres, imgbuf);
    case 4:
      return writebmp(name, xres, yres, imgbuf);
    case 0:
      return writetga(name, xres, yres, imgbuf);
    default:
      printf("Unsupported image format combination\n");
      return 2;
    }
  } else {
    unsigned char *imgbuf = (unsigned char *)img;
    int rc;
    switch (fileformat) {
    case 1:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writeppm(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 2:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writergb(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 3:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writejpeg(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 5:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writepng(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 4:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writebmp(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 0:
      imgbuf = image_rgb24_from_rgb96f(xres, yres, img);
      rc = writetga(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 6:
      imgbuf = image_rgb48be_from_rgb96f(xres, yres, img);
      rc = writeppm48(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    case 7:
      imgbuf = image_rgb48bepl_from_rgb96f(xres, yres, img);
      rc = writepsd48(name, xres, yres, imgbuf);
      free(imgbuf);
      return rc;
    default:
      printf("Unsupported image format combination\n");
      return 2;
    }
  }
}


x86 assembly (clang, -O0):
<writeimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1205 <writeimage+0x35>
movl   $0x6,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
cmpl   $0x0,-0x24(%rbp)
jne    12f6 <writeimage+0x126>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
mov    %rax,-0x48(%rbp)
sub    $0x5,%rax
ja     12de <writeimage+0x10e>
mov    -0x48(%rbp),%rax
lea    0xded(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   10d0 <writeppm@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1080 <writergb@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1090 <writejpeg@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   1030 <writepng@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   10c0 <writebmp@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x30(%rbp),%rcx
call   10a0 <writetga@plt>
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
lea    0xd53(%rip),%rdi
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
mov    %rax,-0x50(%rbp)
sub    $0x7,%rax
ja     150b <writeimage+0x33b>
mov    -0x50(%rbp),%rax
lea    0xce6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   10d0 <writeppm@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1080 <writergb@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1090 <writejpeg@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1030 <writepng@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   10c0 <writebmp@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   10a0 <writetga@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   10f0 <image_rgb48be_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1070 <writeppm48@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <image_rgb48bepl_from_rgb96f@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   10b0 <writepsd48@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    151e <writeimage+0x34e>
lea    0xb26(%rip),%rdi
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeimage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rcx,%rcx
je     1227 <writeimage+0x57>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %r8d,%r8d
je     1231 <writeimage+0x61>
cmp    $0x7,%r9d
ja     1261 <writeimage+0x91>
mov    %r9d,%eax
lea    0xe07(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   10a0 <writetga@plt>
jmp    136c <writeimage+0x19c>
mov    $0x6,%eax
jmp    1378 <writeimage+0x1a8>
cmp    $0x5,%r9d
ja     1261 <writeimage+0x91>
mov    %r9d,%eax
lea    0xddf(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <writetga@plt>
lea    0xdd0(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2,%eax
jmp    1378 <writeimage+0x1a8>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   10d0 <writeppm@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1080 <writergb@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1090 <writejpeg@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   10c0 <writebmp@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10e0 <image_rgb24_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <writepng@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   10f0 <image_rgb48be_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1070 <writeppm48@plt>
jmp    136c <writeimage+0x19c>
mov    %ebp,%edi
mov    %r14d,%esi
mov    %rcx,%rdx
call   1060 <image_rgb48bepl_from_rgb96f@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   10b0 <writepsd48@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1040 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <writeppm@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <writergb@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <writejpeg@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <writebmp@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <writepng@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"Unsupported image format combination\0A\00"
define i32 @writeimage(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%17 = load i8*, i8** %11
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %6
store i32 6, i32* %7
br label %173
20: ; preds = %6
%21 = load i32, i32* %12
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %64
23: ; preds = %20
%24 = load i8*, i8** %11
store i8* %24, i8** %14
%25 = load i32, i32* %13
switch i32 %25, label %62 [
i32 1, label %26
i32 2, label %32
i32 3, label %38
i32 5, label %44
i32 4, label %50
i32 0, label %56
]
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i8*, i8** %14
%31 = call i32 @writeppm(i8* %27, i32 %28, i32 %29, i8* %30)
store i32 %31, i32* %7
br label %173
32: ; preds = %23
%33 = load i8*, i8** %8
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = load i8*, i8** %14
%37 = call i32 @writergb(i8* %33, i32 %34, i32 %35, i8* %36)
store i32 %37, i32* %7
br label %173
38: ; preds = %23
%39 = load i8*, i8** %8
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = load i8*, i8** %14
%43 = call i32 @writejpeg(i8* %39, i32 %40, i32 %41, i8* %42)
store i32 %43, i32* %7
br label %173
44: ; preds = %23
%45 = load i8*, i8** %8
%46 = load i32, i32* %9
%47 = load i32, i32* %10
%48 = load i8*, i8** %14
%49 = call i32 @writepng(i8* %45, i32 %46, i32 %47, i8* %48)
store i32 %49, i32* %7
br label %173
50: ; preds = %23
%51 = load i8*, i8** %8
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = load i8*, i8** %14
%55 = call i32 @writebmp(i8* %51, i32 %52, i32 %53, i8* %54)
store i32 %55, i32* %7
br label %173
56: ; preds = %23
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = load i32, i32* %10
%60 = load i8*, i8** %14
%61 = call i32 @writetga(i8* %57, i32 %58, i32 %59, i8* %60)
store i32 %61, i32* %7
br label %173
62: ; preds = %23
%63 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %7
br label %173
64: ; preds = %20
%65 = load i8*, i8** %11
store i8* %65, i8** %15
%66 = load i32, i32* %13
switch i32 %66, label %171 [
i32 1, label %67
i32 2, label %80
i32 3, label %93
i32 5, label %106
i32 4, label %119
i32 0, label %132
i32 6, label %145
i32 7, label %158
]
67: ; preds = %64
%68 = load i32, i32* %9
%69 = load i32, i32* %10
%70 = load i8*, i8** %11
%71 = call i8* @image_rgb24_from_rgb96f(i32 %68, i32 %69, i8* %70)
store i8* %71, i8** %15
%72 = load i8*, i8** %8
%73 = load i32, i32* %9
%74 = load i32, i32* %10
%75 = load i8*, i8** %15
%76 = call i32 @writeppm(i8* %72, i32 %73, i32 %74, i8* %75)
store i32 %76, i32* %16
%77 = load i8*, i8** %15
%78 = call i32 @free(i8* %77)
%79 = load i32, i32* %16
store i32 %79, i32* %7
br label %173
80: ; preds = %64
%81 = load i32, i32* %9
%82 = load i32, i32* %10
%83 = load i8*, i8** %11
%84 = call i8* @image_rgb24_from_rgb96f(i32 %81, i32 %82, i8* %83)
store i8* %84, i8** %15
%85 = load i8*, i8** %8
%86 = load i32, i32* %9
%87 = load i32, i32* %10
%88 = load i8*, i8** %15
%89 = call i32 @writergb(i8* %85, i32 %86, i32 %87, i8* %88)
store i32 %89, i32* %16
%90 = load i8*, i8** %15
%91 = call i32 @free(i8* %90)
%92 = load i32, i32* %16
store i32 %92, i32* %7
br label %173
93: ; preds = %64
%94 = load i32, i32* %9
%95 = load i32, i32* %10
%96 = load i8*, i8** %11
%97 = call i8* @image_rgb24_from_rgb96f(i32 %94, i32 %95, i8* %96)
store i8* %97, i8** %15
%98 = load i8*, i8** %8
%99 = load i32, i32* %9
%100 = load i32, i32* %10
%101 = load i8*, i8** %15
%102 = call i32 @writejpeg(i8* %98, i32 %99, i32 %100, i8* %101)
store i32 %102, i32* %16
%103 = load i8*, i8** %15
%104 = call i32 @free(i8* %103)
%105 = load i32, i32* %16
store i32 %105, i32* %7
br label %173
106: ; preds = %64
%107 = load i32, i32* %9
%108 = load i32, i32* %10
%109 = load i8*, i8** %11
%110 = call i8* @image_rgb24_from_rgb96f(i32 %107, i32 %108, i8* %109)
store i8* %110, i8** %15
%111 = load i8*, i8** %8
%112 = load i32, i32* %9
%113 = load i32, i32* %10
%114 = load i8*, i8** %15
%115 = call i32 @writepng(i8* %111, i32 %112, i32 %113, i8* %114)
store i32 %115, i32* %16
%116 = load i8*, i8** %15
%117 = call i32 @free(i8* %116)
%118 = load i32, i32* %16
store i32 %118, i32* %7
br label %173
119: ; preds = %64
%120 = load i32, i32* %9
%121 = load i32, i32* %10
%122 = load i8*, i8** %11
%123 = call i8* @image_rgb24_from_rgb96f(i32 %120, i32 %121, i8* %122)
store i8* %123, i8** %15
%124 = load i8*, i8** %8
%125 = load i32, i32* %9
%126 = load i32, i32* %10
%127 = load i8*, i8** %15
%128 = call i32 @writebmp(i8* %124, i32 %125, i32 %126, i8* %127)
store i32 %128, i32* %16
%129 = load i8*, i8** %15
%130 = call i32 @free(i8* %129)
%131 = load i32, i32* %16
store i32 %131, i32* %7
br label %173
132: ; preds = %64
%133 = load i32, i32* %9
%134 = load i32, i32* %10
%135 = load i8*, i8** %11
%136 = call i8* @image_rgb24_from_rgb96f(i32 %133, i32 %134, i8* %135)
store i8* %136, i8** %15
%137 = load i8*, i8** %8
%138 = load i32, i32* %9
%139 = load i32, i32* %10
%140 = load i8*, i8** %15
%141 = call i32 @writetga(i8* %137, i32 %138, i32 %139, i8* %140)
store i32 %141, i32* %16
%142 = load i8*, i8** %15
%143 = call i32 @free(i8* %142)
%144 = load i32, i32* %16
store i32 %144, i32* %7
br label %173
145: ; preds = %64
%146 = load i32, i32* %9
%147 = load i32, i32* %10
%148 = load i8*, i8** %11
%149 = call i8* @image_rgb48be_from_rgb96f(i32 %146, i32 %147, i8* %148)
store i8* %149, i8** %15
%150 = load i8*, i8** %8
%151 = load i32, i32* %9
%152 = load i32, i32* %10
%153 = load i8*, i8** %15
%154 = call i32 @writeppm48(i8* %150, i32 %151, i32 %152, i8* %153)
store i32 %154, i32* %16
%155 = load i8*, i8** %15
%156 = call i32 @free(i8* %155)
%157 = load i32, i32* %16
store i32 %157, i32* %7
br label %173
158: ; preds = %64
%159 = load i32, i32* %9
%160 = load i32, i32* %10
%161 = load i8*, i8** %11
%162 = call i8* @image_rgb48bepl_from_rgb96f(i32 %159, i32 %160, i8* %161)
store i8* %162, i8** %15
%163 = load i8*, i8** %8
%164 = load i32, i32* %9
%165 = load i32, i32* %10
%166 = load i8*, i8** %15
%167 = call i32 @writepsd48(i8* %163, i32 %164, i32 %165, i8* %166)
store i32 %167, i32* %16
%168 = load i8*, i8** %15
%169 = call i32 @free(i8* %168)
%170 = load i32, i32* %16
store i32 %170, i32* %7
br label %173
171: ; preds = %64
%172 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %7
br label %173
173: ; preds = %171, %158, %145, %132, %119, %106, %93, %80, %67, %62, %56, %50, %44, %38, %32, %26, %19
%174 = load i32, i32* %7
ret i32 %174
}

LLVM IR (-O2):
@str.1 = [37 x i8] c"Unsupported image format combination\00"
define i32 @writeimage(i8* %0, i32 %1, i32 %2, i8* %3, i32 %4, i32 %5) {
%7 = icmp eq i8* %3, null
br i1 %7, label %60, label %8
8: ; preds = %6
%9 = icmp eq i32 %4, 0
br i1 %9, label %10, label %25
10: ; preds = %8
switch i32 %5, label %23 [
i32 1, label %11
i32 2, label %13
i32 3, label %15
i32 5, label %17
i32 4, label %19
i32 0, label %21
]
11: ; preds = %10
%12 = tail call i32 @writeppm(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
13: ; preds = %10
%14 = tail call i32 @writergb(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
15: ; preds = %10
%16 = tail call i32 @writejpeg(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
17: ; preds = %10
%18 = tail call i32 @writepng(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
19: ; preds = %10
%20 = tail call i32 @writebmp(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
21: ; preds = %10
%22 = tail call i32 @writetga(i8* %0, i32 %1, i32 %2, i8* %3)
br label %60
23: ; preds = %10
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.1, i64 0, i64 0))
br label %60
25: ; preds = %8
switch i32 %5, label %58 [
i32 1, label %26
i32 2, label %30
i32 3, label %34
i32 5, label %38
i32 4, label %42
i32 0, label %46
i32 6, label %50
i32 7, label %54
]
26: ; preds = %25
%27 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%28 = tail call i32 @writeppm(i8* %0, i32 %1, i32 %2, i8* %27)
%29 = tail call i32 @free(i8* %27)
br label %60
30: ; preds = %25
%31 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%32 = tail call i32 @writergb(i8* %0, i32 %1, i32 %2, i8* %31)
%33 = tail call i32 @free(i8* %31)
br label %60
34: ; preds = %25
%35 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%36 = tail call i32 @writejpeg(i8* %0, i32 %1, i32 %2, i8* %35)
%37 = tail call i32 @free(i8* %35)
br label %60
38: ; preds = %25
%39 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%40 = tail call i32 @writepng(i8* %0, i32 %1, i32 %2, i8* %39)
%41 = tail call i32 @free(i8* %39)
br label %60
42: ; preds = %25
%43 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%44 = tail call i32 @writebmp(i8* %0, i32 %1, i32 %2, i8* %43)
%45 = tail call i32 @free(i8* %43)
br label %60
46: ; preds = %25
%47 = tail call i8* @image_rgb24_from_rgb96f(i32 %1, i32 %2, i8* %3)
%48 = tail call i32 @writetga(i8* %0, i32 %1, i32 %2, i8* %47)
%49 = tail call i32 @free(i8* %47)
br label %60
50: ; preds = %25
%51 = tail call i8* @image_rgb48be_from_rgb96f(i32 %1, i32 %2, i8* %3)
%52 = tail call i32 @writeppm48(i8* %0, i32 %1, i32 %2, i8* %51)
%53 = tail call i32 @free(i8* %51)
br label %60
54: ; preds = %25
%55 = tail call i8* @image_rgb48bepl_from_rgb96f(i32 %1, i32 %2, i8* %3)
%56 = tail call i32 @writepsd48(i8* %0, i32 %1, i32 %2, i8* %55)
%57 = tail call i32 @free(i8* %55)
br label %60
58: ; preds = %25
%59 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.1, i64 0, i64 0))
br label %60
60: ; preds = %26, %30, %34, %38, %42, %46, %50, %54, %58, %11, %13, %15, %17, %19, %21, %23, %6
%61 = phi i32 [ 6, %6 ], [ 2, %23 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ 2, %58 ], [ %56, %54 ], [ %52, %50 ], [ %48, %46 ], [ %44, %42 ], [ %40, %38 ], [ %36, %34 ], [ %32, %30 ], [ %28, %26 ]
ret i32 %61
}