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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
void WriteGrayPixel(int pixel, int pixDataType, char outDataType, FILE *fp) {
  if (outDataType == 'a')
    fprintf(fp, "%d\n", pixel);
  else if (pixDataType == 1)
    putc(pixel, fp);
  else {
    putc(pixel >> 8, fp);
    putc(pixel & 0x00FF, fp);
  }
}


x86 assembly (clang, -O0):
<WriteGrayPixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rcx,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x61,%eax
jne    115c <WriteGrayPixel+0x3c>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xeae(%rip),%rsi
call   1040 <fprintf@plt>
jmp    119d <WriteGrayPixel+0x7d>
cmpl   $0x1,-0x8(%rbp)
jne    1177 <WriteGrayPixel+0x57>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <putc@plt>
jmp    1198 <WriteGrayPixel+0x78>
mov    -0x4(%rbp),%edi
sar    $0x8,%edi
mov    -0x18(%rbp),%rsi
call   1030 <putc@plt>
mov    -0x4(%rbp),%edi
and    $0xff,%edi
mov    -0x18(%rbp),%rsi
call   1030 <putc@plt>
jmp    119d <WriteGrayPixel+0x7d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WriteGrayPixel>:
push   %rbp
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edi,%ebp
cmp    $0x61,%dl
jne    1144 <WriteGrayPixel+0x24>
lea    0xecc(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
cmp    $0x1,%esi
jne    114d <WriteGrayPixel+0x2d>
mov    %ebp,%edi
jmp    115e <WriteGrayPixel+0x3e>
mov    %ebp,%edi
sar    $0x8,%edi
mov    %rbx,%rsi
call   1030 <putc@plt>
movzbl %bpl,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putc@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define void @WriteGrayPixel(i32 %0, i32 %1, i8 signext %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8 %2, i8* %7
store i32* %3, i32** %8
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 97
br i1 %11, label %12, label %16
12: ; preds = %4
%13 = load i32*, i32** %8
%14 = load i32, i32* %5
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %33
16: ; preds = %4
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %5
%21 = load i32*, i32** %8
%22 = call i32 @putc(i32 %20, i32* %21)
br label %32
23: ; preds = %16
%24 = load i32, i32* %5
%25 = ashr i32 %24, 8
%26 = load i32*, i32** %8
%27 = call i32 @putc(i32 %25, i32* %26)
%28 = load i32, i32* %5
%29 = and i32 %28, 255
%30 = load i32*, i32** %8
%31 = call i32 @putc(i32 %29, i32* %30)
br label %32
32: ; preds = %23, %19
br label %33
33: ; preds = %32, %12
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define void @WriteGrayPixel(i32 %0, i32 %1, i8 signext %2, i32* nocapture %3) {
%5 = icmp eq i8 %2, 97
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
8: ; preds = %4
%9 = icmp eq i32 %1, 1
br i1 %9, label %10, label %12
10: ; preds = %8
%11 = tail call i32 @putc(i32 %0, i32* %3)
br label %17
12: ; preds = %8
%13 = ashr i32 %0, 8
%14 = tail call i32 @putc(i32 %13, i32* %3)
%15 = and i32 %0, 255
%16 = tail call i32 @putc(i32 %15, i32* %3)
br label %17
17: ; preds = %10, %12, %6
ret void
}