#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*/ exit(int);
int /*<<< orphan*/ outputimggif(char *, unsigned char *, int, int, int);
int /*<<< orphan*/ outputimgjpg(char *, unsigned char *, int, int, int);
int /*<<< orphan*/ outputimgpm(char *, unsigned char *, int, int, int);
int /*<<< orphan*/ outputimgraw(char *, unsigned char *, int, int, int);
int /*<<< orphan*/ outputimgyuv(char *, unsigned char *, int, int);
int /*<<< orphan*/ printf(char *);
void outputresult(int media_type, char *outfname, unsigned char *RGB, int ny,
                  int nx, int dim) {
  switch (media_type) {
  case 1:
    outputimgyuv(outfname, RGB, ny, nx);
    break;
  case 2:
    outputimgraw(outfname, RGB, ny, nx, dim);
    break;
  case 3:
    outputimgraw(outfname, RGB, ny, nx, dim);
    break;
  case 5:
    outputimgpm(outfname, RGB, ny, nx, dim);
    break;
  case 4:
    outputimgpm(outfname, RGB, ny, nx, dim);
    break;
  case 6:
    outputimgjpg(outfname, RGB, ny, nx, dim);
    break;
  case 9:
    outputimggif(outfname, RGB, ny, nx, dim);
    break;
  default:
    printf("Unknown media type \n");
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<outputresult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x8,%eax
ja     1277 <outputresult+0x107>
mov    -0x30(%rbp),%rax
lea    0xe52(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1080 <outputimgyuv@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <outputimgraw@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1040 <outputimgraw@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1030 <outputimgpm@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1030 <outputimgpm@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1070 <outputimgjpg@plt>
jmp    128d <outputresult+0x11d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1060 <outputimggif@plt>
jmp    128d <outputresult+0x11d>
lea    0xda6(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<outputresult>:
push   %rax
add    $0xffffffff,%edi
cmp    $0x8,%edi
ja     11ea <outputresult+0x7a>
lea    0xe80(%rip),%rax
movslq (%rax,%rdi,4),%rdi
add    %rax,%rdi
jmp    *%rdi
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
pop    %rax
jmp    1050 <outputimgraw@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
pop    %rax
jmp    1040 <outputimgpm@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
pop    %rax
jmp    1080 <outputimgyuv@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
pop    %rax
jmp    1070 <outputimgjpg@plt>
mov    %rsi,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
mov    %r8d,%ecx
mov    %r9d,%r8d
pop    %rax
jmp    1060 <outputimggif@plt>
lea    0xe33(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Unknown media type \0A\00"
define void @outputresult(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%13 = load i32, i32* %7
switch i32 %13, label %62 [
i32 1, label %14
i32 2, label %20
i32 3, label %27
i32 5, label %34
i32 4, label %41
i32 6, label %48
i32 9, label %55
]
14: ; preds = %6
%15 = load i8*, i8** %8
%16 = load i8*, i8** %9
%17 = load i32, i32* %10
%18 = load i32, i32* %11
%19 = call i32 @outputimgyuv(i8* %15, i8* %16, i32 %17, i32 %18)
br label %65
20: ; preds = %6
%21 = load i8*, i8** %8
%22 = load i8*, i8** %9
%23 = load i32, i32* %10
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = call i32 @outputimgraw(i8* %21, i8* %22, i32 %23, i32 %24, i32 %25)
br label %65
27: ; preds = %6
%28 = load i8*, i8** %8
%29 = load i8*, i8** %9
%30 = load i32, i32* %10
%31 = load i32, i32* %11
%32 = load i32, i32* %12
%33 = call i32 @outputimgraw(i8* %28, i8* %29, i32 %30, i32 %31, i32 %32)
br label %65
34: ; preds = %6
%35 = load i8*, i8** %8
%36 = load i8*, i8** %9
%37 = load i32, i32* %10
%38 = load i32, i32* %11
%39 = load i32, i32* %12
%40 = call i32 @outputimgpm(i8* %35, i8* %36, i32 %37, i32 %38, i32 %39)
br label %65
41: ; preds = %6
%42 = load i8*, i8** %8
%43 = load i8*, i8** %9
%44 = load i32, i32* %10
%45 = load i32, i32* %11
%46 = load i32, i32* %12
%47 = call i32 @outputimgpm(i8* %42, i8* %43, i32 %44, i32 %45, i32 %46)
br label %65
48: ; preds = %6
%49 = load i8*, i8** %8
%50 = load i8*, i8** %9
%51 = load i32, i32* %10
%52 = load i32, i32* %11
%53 = load i32, i32* %12
%54 = call i32 @outputimgjpg(i8* %49, i8* %50, i32 %51, i32 %52, i32 %53)
br label %65
55: ; preds = %6
%56 = load i8*, i8** %8
%57 = load i8*, i8** %9
%58 = load i32, i32* %10
%59 = load i32, i32* %11
%60 = load i32, i32* %12
%61 = call i32 @outputimggif(i8* %56, i8* %57, i32 %58, i32 %59, i32 %60)
br label %65
62: ; preds = %6
%63 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%64 = call i32 @exit(i32 -1)
unreachable
65: ; preds = %55, %48, %41, %34, %27, %20, %14
ret void
}

LLVM IR (-O2):
@str = [20 x i8] c"Unknown media type \00"
define void @outputresult(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
switch i32 %0, label %21 [
i32 1, label %7
i32 2, label %9
i32 3, label %11
i32 5, label %13
i32 4, label %15
i32 6, label %17
i32 9, label %19
]
7: ; preds = %6
%8 = tail call i32 @outputimgyuv(i8* %1, i8* %2, i32 %3, i32 %4)
br label %24
9: ; preds = %6
%10 = tail call i32 @outputimgraw(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
11: ; preds = %6
%12 = tail call i32 @outputimgraw(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
13: ; preds = %6
%14 = tail call i32 @outputimgpm(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
15: ; preds = %6
%16 = tail call i32 @outputimgpm(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
17: ; preds = %6
%18 = tail call i32 @outputimgjpg(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
19: ; preds = %6
%20 = tail call i32 @outputimggif(i8* %1, i8* %2, i32 %3, i32 %4, i32 %5)
br label %24
21: ; preds = %6
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %19, %17, %15, %13, %11, %9, %7
ret void
}