#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 */
unsigned int EOF;
scalar_t__ ferror(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
unsigned int getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putEscapeChar(unsigned int);
int /*<<< orphan*/ putchar(unsigned int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main() {
  unsigned int c;
  while ((c = getchar()) != EOF) {
    if (c <= 0x7f) {
      putchar(c);
    } else {
      int i, nc;
      if ((c & 0xE0) == 0xC0) {
        nc = 1;
      } else if ((c & 0xF0) == 0xE0) {
        nc = 2;
      } else if ((c & 0xF8) == 0xF0) {
        nc = 3;
      } else {
        fprintf(stderr, "expand-utf8: invalid UTF-8 header byte %#0x\n", c);
        return 1;
      }
      putEscapeChar(c);
      for (i = 0; i < nc; i++) {
        if ((c = getchar()) == EOF) {
          fprintf(stderr,
                  "expand-utf8: unexpected EOF in multibyte character\n");
          return 1;
        } else if ((c & 0xC0) != 0x80) {
          fprintf(stderr, "expand-utf8: invalid UTF-8 extension byte %#0x\n",
                  c);
          return 1;
        }
        putEscapeChar(c);
      }
    }
  }
  if (ferror(stdin)) {
    perror("expand-utf8");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%eax
je     12e1 <main+0x181>
cmpl   $0x7f,-0x8(%rbp)
ja     119f <main+0x3f>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    12dc <main+0x17c>
mov    -0x8(%rbp),%eax
and    $0xe0,%eax
cmp    $0xc0,%eax
jne    11be <main+0x5e>
movl   $0x1,-0x10(%rbp)
jmp    122c <main+0xcc>
mov    -0x8(%rbp),%eax
and    $0xf0,%eax
cmp    $0xe0,%eax
jne    11dd <main+0x7d>
movl   $0x2,-0x10(%rbp)
jmp    1227 <main+0xc7>
mov    -0x8(%rbp),%eax
and    $0xf8,%eax
cmp    $0xf0,%eax
jne    11fc <main+0x9c>
movl   $0x3,-0x10(%rbp)
jmp    1222 <main+0xc2>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1b8>
jmp    1227 <main+0xc7>
jmp    122c <main+0xcc>
mov    -0x8(%rbp),%edi
call   1070 <putEscapeChar@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12d7 <main+0x177>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2d88(%rip),%rcx
cmp    (%rcx),%eax
jne    1283 <main+0x123>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1b8>
mov    -0x8(%rbp),%eax
and    $0xc0,%eax
cmp    $0x80,%eax
je     12bc <main+0x15c>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1b8>
jmp    12c1 <main+0x161>
mov    -0x8(%rbp),%edi
call   1070 <putEscapeChar@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123b <main+0xdb>
jmp    12dc <main+0x17c>
jmp    116f <main+0xf>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1311 <main+0x1b1>
lea    0xd91(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1318 <main+0x1b8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e6b(%rip),%rbx
cmp    (%rbx),%eax
je     1216 <main+0xb6>
cmp    $0x7f,%eax
ja     1190 <main+0x30>
mov    %eax,%edi
call   1030 <putchar@plt>
jmp    1207 <main+0xa7>
xchg   %ax,%ax
mov    %eax,%ecx
and    $0xe0,%ecx
mov    $0x1,%ebp
cmp    $0xc0,%ecx
je     11d3 <main+0x73>
mov    %eax,%ecx
and    $0xf0,%ecx
mov    $0x2,%ebp
cmp    $0xe0,%ecx
je     11d3 <main+0x73>
mov    %eax,%ecx
and    $0xf8,%ecx
mov    $0x3,%ebp
cmp    $0xf0,%ecx
jne    1277 <main+0x117>
mov    %eax,%edi
call   1070 <putEscapeChar@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
je     1237 <main+0xd7>
mov    %eax,%ecx
and    $0xc0,%ecx
cmp    $0x80,%ecx
jne    1250 <main+0xf0>
mov    %eax,%edi
call   1070 <putEscapeChar@plt>
add    $0xffffffff,%ebp
jne    11e0 <main+0x80>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%rbx),%eax
jne    117d <main+0x1d>
mov    0x2dcb(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
test   %rax,%rax
je     126f <main+0x10f>
lea    0xe61(%rip),%rdi
call   1080 <perror@plt>
jmp    1269 <main+0x109>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1269 <main+0x109>
mov    0x2d79(%rip),%rcx
mov    (%rcx),%edi
lea    0xe01(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d52(%rip),%rcx
mov    (%rcx),%edi
lea    0xd79(%rip),%rsi
jmp    1260 <main+0x100>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"expand-utf8: invalid UTF-8 header byte %x\0A\00"
@.str.1 = [52 x i8] c"expand-utf8: unexpected EOF in multibyte character\0A\00"
@.str.2 = [48 x i8] c"expand-utf8: invalid UTF-8 extension byte %x\0A\00"
@stdin = global i32 0
@.str.3 = [12 x i8] c"expand-utf8\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %66, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %67
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp ule i32 %10, 127
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %2
%14 = call i32 @putchar(i32 %13)
br label %66
15: ; preds = %9
%16 = load i32, i32* %2
%17 = and i32 %16, 224
%18 = icmp eq i32 %17, 192
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %4
br label %36
20: ; preds = %15
%21 = load i32, i32* %2
%22 = and i32 %21, 240
%23 = icmp eq i32 %22, 224
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 2, i32* %4
br label %35
25: ; preds = %20
%26 = load i32, i32* %2
%27 = and i32 %26, 248
%28 = icmp eq i32 %27, 240
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 3, i32* %4
br label %34
30: ; preds = %25
%31 = load i32, i32* @stderr
%32 = load i32, i32* %2
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 1, i32* %1
br label %74
34: ; preds = %29
br label %35
35: ; preds = %34, %24
br label %36
36: ; preds = %35, %19
%37 = load i32, i32* %2
%38 = call i32 @putEscapeChar(i32 %37)
store i32 0, i32* %3
br label %39
39: ; preds = %62, %36
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %65
43: ; preds = %39
%44 = call i32 (...) @getchar()
store i32 %44, i32* %2
%45 = load i32, i32* @EOF
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %74
50: ; preds = %43
%51 = load i32, i32* %2
%52 = and i32 %51, 192
%53 = icmp ne i32 %52, 128
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = load i32, i32* %2
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %56)
store i32 1, i32* %1
br label %74
58: ; preds = %50
br label %59
59: ; preds = %58
%60 = load i32, i32* %2
%61 = call i32 @putEscapeChar(i32 %60)
br label %62
62: ; preds = %59
%63 = load i32, i32* %3
%64 = add nsw i32 %63, 1
store i32 %64, i32* %3
br label %39
65: ; preds = %39
br label %66
66: ; preds = %65, %12
br label %5
67: ; preds = %5
%68 = load i32, i32* @stdin
%69 = call i64 @ferror(i32 %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %74
73: ; preds = %67
store i32 0, i32* %1
br label %74
74: ; preds = %73, %71, %54, %47, %30
%75 = load i32, i32* %1
ret i32 %75
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [45 x i8] c"expand-utf8: invalid UTF-8 header byte %x\0A\00"
@.str.1 = [52 x i8] c"expand-utf8: unexpected EOF in multibyte character\0A\00"
@.str.2 = [48 x i8] c"expand-utf8: invalid UTF-8 extension byte %x\0A\00"
@stdin = global i32 0
@.str.3 = [12 x i8] c"expand-utf8\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %46, label %4
4: ; preds = %0, %42
%5 = phi i32 [ %43, %42 ], [ %1, %0 ]
%6 = icmp ult i32 %5, 128
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @putchar(i32 %5)
br label %42
9: ; preds = %4
%10 = and i32 %5, 224
%11 = icmp eq i32 %10, 192
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = and i32 %5, 240
%14 = icmp eq i32 %13, 224
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = and i32 %5, 248
%17 = icmp eq i32 %16, 240
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %52
21: ; preds = %15, %12, %9
%22 = phi i32 [ 1, %9 ], [ 2, %12 ], [ 3, %15 ]
%23 = tail call i32 @putEscapeChar(i32 %5)
br label %24
24: ; preds = %21, %38
%25 = phi i32 [ 0, %21 ], [ %40, %38 ]
%26 = tail call i32 (...) @getchar()
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %52
32: ; preds = %24
%33 = and i32 %26, 192
%34 = icmp eq i32 %33, 128
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0), i32 %26)
br label %52
38: ; preds = %32
%39 = tail call i32 @putEscapeChar(i32 %26)
%40 = add nuw nsw i32 %25, 1
%41 = icmp eq i32 %40, %22
br i1 %41, label %42, label %24
42: ; preds = %38, %7
%43 = tail call i32 (...) @getchar()
%44 = load i32, i32* @EOF
%45 = icmp eq i32 %43, %44
br i1 %45, label %46, label %4
46: ; preds = %42, %0
%47 = load i32, i32* @stdin
%48 = tail call i64 @ferror(i32 %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %46
%51 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %18, %35, %29, %46, %50
%53 = phi i32 [ 1, %50 ], [ 0, %46 ], [ 1, %29 ], [ 1, %35 ], [ 1, %18 ]
ret i32 %53
}