#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 MB_CUR_MAX;
int getc(int /*<<< orphan*/ *);
int mblen(char *, int);
int /*<<< orphan*/ printf(char *);
char *GetAChar(FILE *ifile) {
  int c;
  static char mbyte[32];
  int length;
  length = 0;
  if (((c = getc(ifile)) == EOF) || (c == '\0')) {
    *mbyte = '\0';
    return mbyte;
  }
  while (1) {
    mbyte[length++] = c;
    mbyte[length] = '\0';
    if (mblen(mbyte, length) != -1)
      return mbyte;
    if (length == MB_CUR_MAX) {
      printf("An invalid multi-byte character was found in the input");
      mbyte[0] = ' ';
      mbyte[1] = '\0';
      return mbyte;
    }
    if ((c = getc(ifile)) == EOF) {
      printf("End-of-file found within a multi-byte character");
      mbyte[0] = '\0';
      return mbyte;
    }
  }
}


x86 assembly (clang, -O0):
<GetAChar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
je     1168 <GetAChar+0x38>
cmpl   $0x0,-0x14(%rbp)
jne    117f <GetAChar+0x4f>
movb   $0x0,0x2ee1(%rip)
lea    0x2eda(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1257 <GetAChar+0x127>
jmp    1184 <GetAChar+0x54>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
movslq %eax,%rcx
lea    0x2eb2(%rip),%rax
mov    %dl,(%rax,%rcx,1)
movslq -0x18(%rbp),%rcx
lea    0x2ea4(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%esi
lea    0x2e96(%rip),%rdi
call   1030 <mblen@plt>
cmp    $0xffffffff,%eax
je     11d8 <GetAChar+0xa8>
lea    0x2e81(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1257 <GetAChar+0x127>
mov    -0x18(%rbp),%eax
mov    0x2e16(%rip),%rcx
cmp    (%rcx),%eax
jne    1214 <GetAChar+0xe4>
lea    0xe0f(%rip),%rdi
call   1040 <printf@plt>
movb   $0x20,0x2e53(%rip)
movb   $0x0,0x2e4d(%rip)
lea    0x2e45(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1257 <GetAChar+0x127>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2db9(%rip),%rcx
cmp    (%rcx),%eax
jne    1252 <GetAChar+0x122>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,0x2e0e(%rip)
lea    0x2e07(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1257 <GetAChar+0x127>
jmp    1184 <GetAChar+0x54>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetAChar>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1050 <getc@plt>
test   %eax,%eax
je     11b0 <GetAChar+0x80>
mov    0x2e94(%rip),%r12
cmp    (%r12),%eax
je     11b0 <GetAChar+0x80>
mov    $0x1,%ebx
lea    0x2ef2(%rip),%r15
mov    0x2e93(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %al,-0x1(%rbx,%r15,1)
movb   $0x0,(%rbx,%r15,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1030 <mblen@plt>
cmp    $0xffffffff,%eax
jne    11ce <GetAChar+0x9e>
mov    0x0(%r13),%eax
cmp    %rax,%rbx
je     11b9 <GetAChar+0x89>
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <getc@plt>
cmp    (%r12),%eax
jne    1170 <GetAChar+0x40>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
movb   $0x0,0x2e99(%rip)
jmp    11ce <GetAChar+0x9e>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
movw   $0x20,0x2e82(%rip)
lea    0x2e7b(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@GetAChar.mbyte = internal global [32 x i8] zeroinitializer
@EOF = global i32 0
@MB_CUR_MAX = global i32 0
@.str = [55 x i8] c"An invalid multi-byte character was found in the input\00"
@.str.1 = [48 x i8] c"End-of-file found within a multi-byte character\00"
define i8* @GetAChar(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
%6 = load i32*, i32** %3
%7 = call i32 @getc(i32* %6)
store i32 %7, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10, %1
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i8** %2
br label %43
14: ; preds = %10
br label %15
15: ; preds = %14, %42
%16 = load i32, i32* %4
%17 = trunc i32 %16 to i8
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds [32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 %20
store i8 %17, i8* %21
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 %23
store i8 0, i8* %24
%25 = load i32, i32* %5
%26 = call i32 @mblen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i32 %25)
%27 = icmp ne i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %15
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i8** %2
br label %43
29: ; preds = %15
%30 = load i32, i32* %5
%31 = load i32, i32* @MB_CUR_MAX
%32 = icmp eq i32 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i8 32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 1)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i8** %2
br label %43
35: ; preds = %29
%36 = load i32*, i32** %3
%37 = call i32 @getc(i32* %36)
store i32 %37, i32* %4
%38 = load i32, i32* @EOF
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i8** %2
br label %43
42: ; preds = %35
br label %15
43: ; preds = %40, %33, %28, %13
%44 = load i8*, i8** %2
ret i8* %44
}

LLVM IR (-O2):
@GetAChar.mbyte = internal global [32 x i8] zeroinitializer
@EOF = global i32 0
@MB_CUR_MAX = global i32 0
@.str = [55 x i8] c"An invalid multi-byte character was found in the input\00"
@.str.1 = [48 x i8] c"End-of-file found within a multi-byte character\00"
define i8* @GetAChar(i32* nocapture %0) {
%2 = tail call i32 @getc(i32* %0)
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
%5 = icmp eq i32 %2, 0
%6 = or i1 %5, %4
br i1 %6, label %7, label %8
7: ; preds = %1
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
br label %30
8: ; preds = %1, %24
%9 = phi i64 [ %12, %24 ], [ 0, %1 ]
%10 = phi i32 [ %25, %24 ], [ %2, %1 ]
%11 = trunc i32 %10 to i8
%12 = add nuw nsw i64 %9, 1
%13 = getelementptr inbounds [32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 %9
store i8 %11, i8* %13
%14 = getelementptr inbounds [32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 %12
store i8 0, i8* %14
%15 = trunc i64 %12 to i32
%16 = tail call i32 @mblen(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %30
18: ; preds = %8
%19 = load i32, i32* @MB_CUR_MAX
%20 = zext i32 %19 to i64
%21 = icmp eq i64 %12, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
store i8 32, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 1)
br label %30
24: ; preds = %18
%25 = tail call i32 @getc(i32* %0)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %8
28: ; preds = %24
%29 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
store i8 0, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
br label %30
30: ; preds = %8, %28, %22, %7
ret i8* getelementptr inbounds ([32 x i8], [32 x i8]* @GetAChar.mbyte, i64 0, i64 0)
}