#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 EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int ReadGrayPixel(int pixDataType, char inpDataType, FILE *fp) {
  int pixel;
  if (inpDataType == 'a')
    if (fscanf(fp, "%d", &pixel) != 1) {
      fprintf(stderr, "ReadGrayPixel: while reading file\n");
      return EOF;
    } else
      return pixel;
  else if (pixDataType == 1)
    return getc(fp);
  else {
    int c;
    if ((c = getc(fp)) == EOF) {
      fprintf(stderr, "ReadGrayPixel: while reading file\n");
      return EOF;
    }
    pixel = c << 8;
    if ((c = getc(fp)) == EOF) {
      fprintf(stderr, "ReadGrayPixel: while reading file\n");
      return EOF;
    }
    return pixel + c;
  }
}


x86 assembly (clang, -O0):
<ReadGrayPixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x61,%eax
jne    11a0 <ReadGrayPixel+0x70>
mov    -0x18(%rbp),%rdi
lea    0xea3(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <fscanf@plt>
cmp    $0x1,%eax
je     1195 <ReadGrayPixel+0x65>
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <ReadGrayPixel+0x11f>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <ReadGrayPixel+0x11f>
cmpl   $0x1,-0x8(%rbp)
jne    11bb <ReadGrayPixel+0x8b>
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x4(%rbp)
jmp    124f <ReadGrayPixel+0x11f>
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
jne    11fc <ReadGrayPixel+0xcc>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <ReadGrayPixel+0x11f>
mov    -0x20(%rbp),%eax
shl    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2dd0(%rip),%rcx
cmp    (%rcx),%eax
jne    1246 <ReadGrayPixel+0x116>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    124f <ReadGrayPixel+0x11f>
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadGrayPixel>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
cmp    $0x61,%sil
jne    1160 <ReadGrayPixel+0x30>
lea    0xeb8(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r14,%rdi
call   1030 <fscanf@plt>
cmp    $0x1,%eax
jne    11a4 <ReadGrayPixel+0x74>
mov    0xc(%rsp),%ebx
jmp    11c9 <ReadGrayPixel+0x99>
mov    %edi,%ebp
mov    %r14,%rdi
call   1050 <getc@plt>
mov    %eax,%ebx
cmp    $0x1,%ebp
je     11c9 <ReadGrayPixel+0x99>
mov    0x2e70(%rip),%rbp
cmp    0x0(%rbp),%ebx
je     118a <ReadGrayPixel+0x5a>
mov    %r14,%rdi
call   1050 <getc@plt>
cmp    0x0(%rbp),%eax
jne    11c4 <ReadGrayPixel+0x94>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe69(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x0(%rbp),%ebx
jmp    11c9 <ReadGrayPixel+0x99>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%ebx
jmp    11c9 <ReadGrayPixel+0x99>
shl    $0x8,%ebx
add    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ReadGrayPixel: while reading file\0A\00"
@EOF = global i32 0
define i32 @ReadGrayPixel(i32 %0, i8 signext %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8 %1, i8* %6
store i32* %2, i32** %7
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 97
br i1 %12, label %13, label %23
13: ; preds = %3
%14 = load i32*, i32** %7
%15 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32, i32* @EOF
store i32 %20, i32* %4
br label %53
21: ; preds = %13
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %53
23: ; preds = %3
%24 = load i32, i32* %5
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32*, i32** %7
%28 = call i32 @getc(i32* %27)
store i32 %28, i32* %4
br label %53
29: ; preds = %23
%30 = load i32*, i32** %7
%31 = call i32 @getc(i32* %30)
store i32 %31, i32* %9
%32 = load i32, i32* @EOF
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EOF
store i32 %37, i32* %4
br label %53
38: ; preds = %29
%39 = load i32, i32* %9
%40 = shl i32 %39, 8
store i32 %40, i32* %8
%41 = load i32*, i32** %7
%42 = call i32 @getc(i32* %41)
store i32 %42, i32* %9
%43 = load i32, i32* @EOF
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* @EOF
store i32 %48, i32* %4
br label %53
49: ; preds = %38
%50 = load i32, i32* %8
%51 = load i32, i32* %9
%52 = add nsw i32 %50, %51
store i32 %52, i32* %4
br label %53
53: ; preds = %49, %45, %34, %26, %21, %17
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"ReadGrayPixel: while reading file\0A\00"
@EOF = global i32 0
define i32 @ReadGrayPixel(i32 %0, i8 signext %1, i32* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i8 %1, 97
br i1 %6, label %7, label %16
7: ; preds = %3
%8 = call i32 @fscanf(i32* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%9 = icmp eq i32 %8, 1
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EOF
br label %37
14: ; preds = %7
%15 = load i32, i32* %4
br label %37
16: ; preds = %3
%17 = icmp eq i32 %0, 1
%18 = tail call i32 @getc(i32* %2)
br i1 %17, label %37, label %19
19: ; preds = %16
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %26
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%25 = load i32, i32* @EOF
br label %37
26: ; preds = %19
%27 = tail call i32 @getc(i32* %2)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @EOF
br label %37
34: ; preds = %26
%35 = shl i32 %18, 8
%36 = add nsw i32 %35, %27
br label %37
37: ; preds = %16, %22, %30, %34, %14, %10
%38 = phi i32 [ %13, %10 ], [ %15, %14 ], [ %25, %22 ], [ %33, %30 ], [ %36, %34 ], [ %18, %16 ]
ret i32 %38
}