signed int writeimage(char *name, signed int xres, signed int yres, void *img,
                      signed int imgbufferformat, signed int fileformat) {
  if (img == ((void *)0))
    return 6;
  signed int return_value_writeppm$1;
  signed int return_value_writergb$2;
  signed int return_value_writejpeg$3;
  signed int return_value_writepng$4;
  signed int return_value_writebmp$5;
  signed int return_value_writetga$6;
  if (imgbufferformat == 0) {
    unsigned char *writeimage$$1$$1$$imgbuf = (unsigned char *)img;
    switch (fileformat) {
    case 1: {
      return_value_writeppm$1 =
          writeppm(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writeppm$1;
    }
    case 2: {
      return_value_writergb$2 =
          writergb(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writergb$2;
    }
    case 3: {
      return_value_writejpeg$3 =
          writejpeg(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writejpeg$3;
    }
    case 5: {
      return_value_writepng$4 =
          writepng(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writepng$4;
    }
    case 4: {
      return_value_writebmp$5 =
          writebmp(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writebmp$5;
    }
    case 0: {
      return_value_writetga$6 =
          writetga(name, xres, yres, writeimage$$1$$1$$imgbuf);
      return return_value_writetga$6;
    }
    default: {
      printf("Unsupported image format combination\n");
      return 2;
    }
    }
  } else {
    unsigned char *writeimage$$1$$2$$imgbuf = (unsigned char *)img;
    signed int rc;
    switch (fileformat) {
    case 1: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writeppm(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 2: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writergb(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 3: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writejpeg(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 5: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writepng(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 4: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writebmp(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 0: {
      writeimage$$1$$2$$imgbuf =
          image_rgb24_from_rgb96f(xres, yres, (float *)img);
      rc = writetga(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 6: {
      writeimage$$1$$2$$imgbuf =
          image_rgb48be_from_rgb96f(xres, yres, (float *)img);
      rc = writeppm48(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    case 7: {
      writeimage$$1$$2$$imgbuf =
          image_rgb48bepl_from_rgb96f(xres, yres, (float *)img);
      rc = writepsd48(name, xres, yres, writeimage$$1$$2$$imgbuf);
      free((void *)writeimage$$1$$2$$imgbuf);
      return rc;
    }
    default: {
      printf("Unsupported image format combination\n");
      return 2;
    }
    }
  }
}


x86 assembly (clang, -O0):
<writeimage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    1582 <writeimage+0x3b2>
cmpl   $0x0,-0x24(%rbp)
jne    1328 <writeimage+0x158>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%eax
mov    %rax,-0x60(%rbp)
sub    $0x5,%rax
ja     130e <writeimage+0x13e>
mov    -0x60(%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    -0x48(%rbp),%rcx
mov    $0x0,%al
call   10d0 <writeppm@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1080 <writergb@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1090 <writejpeg@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   1030 <writepng@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   10c0 <writebmp@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    $0x0,%al
call   10a0 <writetga@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
lea    0xd23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%eax
mov    %rax,-0x68(%rbp)
sub    $0x7,%rax
ja     156d <writeimage+0x39d>
mov    -0x68(%rbp),%rax
lea    0xcb4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   10d0 <writeppm@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   1080 <writergb@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   1090 <writejpeg@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   1030 <writepng@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   10c0 <writebmp@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10e0 <image_rgb24_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   10a0 <writetga@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10f0 <image_rgb48be_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   1070 <writeppm48@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x20(%rbp),%rdx
mov    $0x0,%al
call   1050 <image_rgb48bepl_from_rgb96f@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x50(%rbp),%rcx
mov    $0x0,%al
call   10b0 <writepsd48@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1582 <writeimage+0x3b2>
lea    0xac4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeimage>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rcx,%rcx
je     1228 <writeimage+0x58>
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,%r14
test   %r8d,%r8d
je     1232 <writeimage+0x62>
cmp    $0x7,%r9d
ja     1263 <writeimage+0x93>
mov    %r9d,%eax
lea    0xe08(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   10a0 <writetga@plt>
jmp    137c <writeimage+0x1ac>
mov    $0x6,%eax
jmp    1388 <writeimage+0x1b8>
cmp    $0x5,%r9d
ja     1263 <writeimage+0x93>
mov    %r9d,%eax
lea    0xdde(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <writetga@plt>
lea    0xdce(%rip),%rdi
call   1050 <puts@plt>
mov    $0x2,%eax
jmp    1388 <writeimage+0x1b8>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   10d0 <writeppm@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1080 <writergb@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1090 <writejpeg@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   10c0 <writebmp@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <image_rgb24_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1030 <writepng@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   10f0 <image_rgb48be_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
call   1070 <writeppm48@plt>
jmp    137c <writeimage+0x1ac>
mov    %ebp,%edi
mov    %ebx,%esi
mov    %rcx,%rdx
xor    %eax,%eax
call   1060 <image_rgb48bepl_from_rgb96f@plt>
movslq %eax,%r15
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
xor    %eax,%eax
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    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10d0 <writeppm@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <writergb@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <writejpeg@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <writebmp@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
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 i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i8*
%22 = 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
%23 = load i8*, i8** %11
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %6
store i32 6, i32* %7
br label %201
26: ; preds = %6
%27 = load i32, i32* %12
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %76
29: ; preds = %26
%30 = load i8*, i8** %11
store i8* %30, i8** %20
%31 = load i32, i32* %13
switch i32 %31, label %74 [
i32 1, label %32
i32 2, label %39
i32 3, label %46
i32 5, label %53
i32 4, label %60
i32 0, label %67
]
32: ; preds = %29
%33 = load i8*, i8** %8
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = load i8*, i8** %20
%37 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm to i32 (i8*, i32, i32, i8*, ...)*)(i8* %33, i32 %34, i32 %35, i8* %36)
store i32 %37, i32* %14
%38 = load i32, i32* %14
store i32 %38, i32* %7
br label %201
39: ; preds = %29
%40 = load i8*, i8** %8
%41 = load i32, i32* %9
%42 = load i32, i32* %10
%43 = load i8*, i8** %20
%44 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writergb to i32 (i8*, i32, i32, i8*, ...)*)(i8* %40, i32 %41, i32 %42, i8* %43)
store i32 %44, i32* %15
%45 = load i32, i32* %15
store i32 %45, i32* %7
br label %201
46: ; preds = %29
%47 = load i8*, i8** %8
%48 = load i32, i32* %9
%49 = load i32, i32* %10
%50 = load i8*, i8** %20
%51 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writejpeg to i32 (i8*, i32, i32, i8*, ...)*)(i8* %47, i32 %48, i32 %49, i8* %50)
store i32 %51, i32* %16
%52 = load i32, i32* %16
store i32 %52, i32* %7
br label %201
53: ; preds = %29
%54 = load i8*, i8** %8
%55 = load i32, i32* %9
%56 = load i32, i32* %10
%57 = load i8*, i8** %20
%58 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepng to i32 (i8*, i32, i32, i8*, ...)*)(i8* %54, i32 %55, i32 %56, i8* %57)
store i32 %58, i32* %17
%59 = load i32, i32* %17
store i32 %59, i32* %7
br label %201
60: ; preds = %29
%61 = load i8*, i8** %8
%62 = load i32, i32* %9
%63 = load i32, i32* %10
%64 = load i8*, i8** %20
%65 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writebmp to i32 (i8*, i32, i32, i8*, ...)*)(i8* %61, i32 %62, i32 %63, i8* %64)
store i32 %65, i32* %18
%66 = load i32, i32* %18
store i32 %66, i32* %7
br label %201
67: ; preds = %29
%68 = load i8*, i8** %8
%69 = load i32, i32* %9
%70 = load i32, i32* %10
%71 = load i8*, i8** %20
%72 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writetga to i32 (i8*, i32, i32, i8*, ...)*)(i8* %68, i32 %69, i32 %70, i8* %71)
store i32 %72, i32* %19
%73 = load i32, i32* %19
store i32 %73, i32* %7
br label %201
74: ; preds = %29
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %7
br label %201
76: ; preds = %26
%77 = load i8*, i8** %11
store i8* %77, i8** %21
%78 = load i32, i32* %13
switch i32 %78, label %199 [
i32 1, label %79
i32 2, label %94
i32 3, label %109
i32 5, label %124
i32 4, label %139
i32 0, label %154
i32 6, label %169
i32 7, label %184
]
79: ; preds = %76
%80 = load i32, i32* %9
%81 = load i32, i32* %10
%82 = load i8*, i8** %11
%83 = bitcast i8* %82 to float*
%84 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %80, i32 %81, float* %83)
%85 = sext i32 %84 to i64
%86 = inttoptr i64 %85 to i8*
store i8* %86, i8** %21
%87 = load i8*, i8** %8
%88 = load i32, i32* %9
%89 = load i32, i32* %10
%90 = load i8*, i8** %21
%91 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm to i32 (i8*, i32, i32, i8*, ...)*)(i8* %87, i32 %88, i32 %89, i8* %90)
store i32 %91, i32* %22
%92 = load i8*, i8** %21
%93 = load i32, i32* %22
store i32 %93, i32* %7
br label %201
94: ; preds = %76
%95 = load i32, i32* %9
%96 = load i32, i32* %10
%97 = load i8*, i8** %11
%98 = bitcast i8* %97 to float*
%99 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %95, i32 %96, float* %98)
%100 = sext i32 %99 to i64
%101 = inttoptr i64 %100 to i8*
store i8* %101, i8** %21
%102 = load i8*, i8** %8
%103 = load i32, i32* %9
%104 = load i32, i32* %10
%105 = load i8*, i8** %21
%106 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writergb to i32 (i8*, i32, i32, i8*, ...)*)(i8* %102, i32 %103, i32 %104, i8* %105)
store i32 %106, i32* %22
%107 = load i8*, i8** %21
%108 = load i32, i32* %22
store i32 %108, i32* %7
br label %201
109: ; preds = %76
%110 = load i32, i32* %9
%111 = load i32, i32* %10
%112 = load i8*, i8** %11
%113 = bitcast i8* %112 to float*
%114 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %110, i32 %111, float* %113)
%115 = sext i32 %114 to i64
%116 = inttoptr i64 %115 to i8*
store i8* %116, i8** %21
%117 = load i8*, i8** %8
%118 = load i32, i32* %9
%119 = load i32, i32* %10
%120 = load i8*, i8** %21
%121 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writejpeg to i32 (i8*, i32, i32, i8*, ...)*)(i8* %117, i32 %118, i32 %119, i8* %120)
store i32 %121, i32* %22
%122 = load i8*, i8** %21
%123 = load i32, i32* %22
store i32 %123, i32* %7
br label %201
124: ; preds = %76
%125 = load i32, i32* %9
%126 = load i32, i32* %10
%127 = load i8*, i8** %11
%128 = bitcast i8* %127 to float*
%129 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %125, i32 %126, float* %128)
%130 = sext i32 %129 to i64
%131 = inttoptr i64 %130 to i8*
store i8* %131, i8** %21
%132 = load i8*, i8** %8
%133 = load i32, i32* %9
%134 = load i32, i32* %10
%135 = load i8*, i8** %21
%136 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepng to i32 (i8*, i32, i32, i8*, ...)*)(i8* %132, i32 %133, i32 %134, i8* %135)
store i32 %136, i32* %22
%137 = load i8*, i8** %21
%138 = load i32, i32* %22
store i32 %138, i32* %7
br label %201
139: ; preds = %76
%140 = load i32, i32* %9
%141 = load i32, i32* %10
%142 = load i8*, i8** %11
%143 = bitcast i8* %142 to float*
%144 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %140, i32 %141, float* %143)
%145 = sext i32 %144 to i64
%146 = inttoptr i64 %145 to i8*
store i8* %146, i8** %21
%147 = load i8*, i8** %8
%148 = load i32, i32* %9
%149 = load i32, i32* %10
%150 = load i8*, i8** %21
%151 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writebmp to i32 (i8*, i32, i32, i8*, ...)*)(i8* %147, i32 %148, i32 %149, i8* %150)
store i32 %151, i32* %22
%152 = load i8*, i8** %21
%153 = load i32, i32* %22
store i32 %153, i32* %7
br label %201
154: ; preds = %76
%155 = load i32, i32* %9
%156 = load i32, i32* %10
%157 = load i8*, i8** %11
%158 = bitcast i8* %157 to float*
%159 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %155, i32 %156, float* %158)
%160 = sext i32 %159 to i64
%161 = inttoptr i64 %160 to i8*
store i8* %161, i8** %21
%162 = load i8*, i8** %8
%163 = load i32, i32* %9
%164 = load i32, i32* %10
%165 = load i8*, i8** %21
%166 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writetga to i32 (i8*, i32, i32, i8*, ...)*)(i8* %162, i32 %163, i32 %164, i8* %165)
store i32 %166, i32* %22
%167 = load i8*, i8** %21
%168 = load i32, i32* %22
store i32 %168, i32* %7
br label %201
169: ; preds = %76
%170 = load i32, i32* %9
%171 = load i32, i32* %10
%172 = load i8*, i8** %11
%173 = bitcast i8* %172 to float*
%174 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb48be_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %170, i32 %171, float* %173)
%175 = sext i32 %174 to i64
%176 = inttoptr i64 %175 to i8*
store i8* %176, i8** %21
%177 = load i8*, i8** %8
%178 = load i32, i32* %9
%179 = load i32, i32* %10
%180 = load i8*, i8** %21
%181 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm48 to i32 (i8*, i32, i32, i8*, ...)*)(i8* %177, i32 %178, i32 %179, i8* %180)
store i32 %181, i32* %22
%182 = load i8*, i8** %21
%183 = load i32, i32* %22
store i32 %183, i32* %7
br label %201
184: ; preds = %76
%185 = load i32, i32* %9
%186 = load i32, i32* %10
%187 = load i8*, i8** %11
%188 = bitcast i8* %187 to float*
%189 = call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb48bepl_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %185, i32 %186, float* %188)
%190 = sext i32 %189 to i64
%191 = inttoptr i64 %190 to i8*
store i8* %191, i8** %21
%192 = load i8*, i8** %8
%193 = load i32, i32* %9
%194 = load i32, i32* %10
%195 = load i8*, i8** %21
%196 = call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepsd48 to i32 (i8*, i32, i32, i8*, ...)*)(i8* %192, i32 %193, i32 %194, i8* %195)
store i32 %196, i32* %22
%197 = load i8*, i8** %21
%198 = load i32, i32* %22
store i32 %198, i32* %7
br label %201
199: ; preds = %76
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
store i32 2, i32* %7
br label %201
201: ; preds = %199, %184, %169, %154, %139, %124, %109, %94, %79, %74, %67, %60, %53, %46, %39, %32, %25
%202 = load i32, i32* %7
ret i32 %202
}

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 %76, 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 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
13: ; preds = %10
%14 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writergb to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
15: ; preds = %10
%16 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writejpeg to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
17: ; preds = %10
%18 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepng to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
19: ; preds = %10
%20 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writebmp to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
21: ; preds = %10
%22 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writetga to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %3)
br label %76
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 %76
25: ; preds = %8
switch i32 %5, label %74 [
i32 1, label %26
i32 2, label %32
i32 3, label %38
i32 5, label %44
i32 4, label %50
i32 0, label %56
i32 6, label %62
i32 7, label %68
]
26: ; preds = %25
%27 = bitcast i8* %3 to float*
%28 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %27)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8*
%31 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %30)
tail call void @free(i8* %30)
br label %76
32: ; preds = %25
%33 = bitcast i8* %3 to float*
%34 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %33)
%35 = sext i32 %34 to i64
%36 = inttoptr i64 %35 to i8*
%37 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writergb to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %36)
tail call void @free(i8* %36)
br label %76
38: ; preds = %25
%39 = bitcast i8* %3 to float*
%40 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %39)
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i8*
%43 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writejpeg to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %42)
tail call void @free(i8* %42)
br label %76
44: ; preds = %25
%45 = bitcast i8* %3 to float*
%46 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %45)
%47 = sext i32 %46 to i64
%48 = inttoptr i64 %47 to i8*
%49 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepng to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %48)
tail call void @free(i8* %48)
br label %76
50: ; preds = %25
%51 = bitcast i8* %3 to float*
%52 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %51)
%53 = sext i32 %52 to i64
%54 = inttoptr i64 %53 to i8*
%55 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writebmp to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %54)
tail call void @free(i8* %54)
br label %76
56: ; preds = %25
%57 = bitcast i8* %3 to float*
%58 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb24_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %57)
%59 = sext i32 %58 to i64
%60 = inttoptr i64 %59 to i8*
%61 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writetga to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %60)
tail call void @free(i8* %60)
br label %76
62: ; preds = %25
%63 = bitcast i8* %3 to float*
%64 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb48be_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %63)
%65 = sext i32 %64 to i64
%66 = inttoptr i64 %65 to i8*
%67 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writeppm48 to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %66)
tail call void @free(i8* %66)
br label %76
68: ; preds = %25
%69 = bitcast i8* %3 to float*
%70 = tail call i32 (i32, i32, float*, ...) bitcast (i32 (...)* @image_rgb48bepl_from_rgb96f to i32 (i32, i32, float*, ...)*)(i32 %1, i32 %2, float* %69)
%71 = sext i32 %70 to i64
%72 = inttoptr i64 %71 to i8*
%73 = tail call i32 (i8*, i32, i32, i8*, ...) bitcast (i32 (...)* @writepsd48 to i32 (i8*, i32, i32, i8*, ...)*)(i8* %0, i32 %1, i32 %2, i8* %72)
tail call void @free(i8* %72)
br label %76
74: ; preds = %25
%75 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.1, i64 0, i64 0))
br label %76
76: ; preds = %23, %21, %19, %17, %15, %13, %11, %74, %68, %62, %56, %50, %44, %38, %32, %26, %6
%77 = phi i32 [ 6, %6 ], [ 2, %23 ], [ %22, %21 ], [ %20, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ], [ 2, %74 ], [ %73, %68 ], [ %67, %62 ], [ %61, %56 ], [ %55, %50 ], [ %49, %44 ], [ %43, %38 ], [ %37, %32 ], [ %31, %26 ]
ret i32 %77
}