#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*/ exit(int);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
char readChar(FILE *fp) {
  int result;
  char x;
  result = fscanf(fp, " %c", &x);
  if (result == EOF) {
    return -1;
  }
  if (result == 0) {
    fprintf(stderr,
            "SCAN ERROR: attempt to read a non-whitespace character failed\n");
    fprintf(stderr, "offending character was <%c>\n", fgetc(fp));
    exit(2);
  }
  return x;
}


x86 assembly (clang, -O0):
<readChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x15(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    117e <readChar+0x3e>
movb   $0xff,-0x1(%rbp)
jmp    11d7 <readChar+0x97>
cmpl   $0x0,-0x14(%rbp)
jne    11d1 <readChar+0x91>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>
mov    -0x15(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readChar>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb3(%rip),%rsi
lea    0x7(%rsp),%rdx
call   1030 <fscanf@plt>
mov    %eax,%ecx
mov    0x2e88(%rip),%rdx
mov    $0xff,%al
cmp    (%rdx),%ecx
je     116e <readChar+0x2e>
test   %ecx,%ecx
je     1175 <readChar+0x35>
mov    0x7(%rsp),%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e5c(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x0(%rbp),%ebp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
lea    0xea4(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c" %c\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [63 x i8] c"SCAN ERROR: attempt to read a non-whitespace character failed\0A\00"
@.str.2 = [30 x i8] c"offending character was <%c>\0A\00"
define signext i8 @readChar(i32* %0) {
%2 = alloca i8
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i8 -1, i8* %2
br label %25
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = load i32*, i32** %3
%20 = call i32 @fgetc(i32* %19)
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %12
%24 = load i8, i8* %5
store i8 %24, i8* %2
br label %25
25: ; preds = %23, %11
%26 = load i8, i8* %2
ret i8 %26
}

LLVM IR (-O2):
@.str = [4 x i8] c" %c\00"
@EOF = global i32 0
@stderr = global i32 0
@.str.1 = [63 x i8] c"SCAN ERROR: attempt to read a non-whitespace character failed\0A\00"
@.str.2 = [30 x i8] c"offending character was <%c>\0A\00"
define signext i8 @readChar(i32* nocapture %0) {
%2 = alloca i8
%3 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = icmp eq i32 %3, 0
br i1 %7, label %8, label %15
8: ; preds = %6
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = call i32 @fgetc(i32* %0)
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %6
%16 = load i8, i8* %2
br label %17
17: ; preds = %1, %15
%18 = phi i8 [ %16, %15 ], [ -1, %1 ]
ret i8 %18
}