#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 fgetc(int /*<<< orphan*/ *);
int read_latin1(FILE *f, char buf[4]) {
  int c = fgetc(f);
  if (c == EOF)
    return -1;
  if (c <= 127) {
    buf[0] = (char)c;
    return 1;
  }
  buf[0] = 0xC0 + ((c >> 6) & 0x1f);
  buf[1] = 0x80 + (c & 0x3f);
  return 2;
}


x86 assembly (clang, -O0):
<read_latin1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2eb2(%rip),%rcx
cmp    (%rcx),%eax
jne    114a <read_latin1+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    119c <read_latin1+0x8c>
cmpl   $0x7f,-0x1c(%rbp)
jg     116b <read_latin1+0x5b>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    119c <read_latin1+0x8c>
mov    -0x1c(%rbp),%eax
sar    $0x6,%eax
and    $0x1f,%eax
add    $0xc0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
and    $0x3f,%eax
add    $0x80,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_latin1>:
push   %rbx
mov    %rsi,%rbx
call   1030 <fgetc@plt>
mov    0x2ec8(%rip),%rdx
mov    $0xffffffff,%ecx
cmp    (%rdx),%eax
je     1150 <read_latin1+0x40>
cmp    $0x7f,%eax
jg     1137 <read_latin1+0x27>
mov    %al,(%rbx)
mov    $0x1,%ecx
jmp    1150 <read_latin1+0x40>
mov    %eax,%ecx
shr    $0x6,%ecx
and    $0x1f,%cl
or     $0xc0,%cl
mov    %cl,(%rbx)
and    $0x3f,%al
or     $0x80,%al
mov    %al,0x1(%rbx)
mov    $0x2,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @read_latin1(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i32*, i32** %4
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %35
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp sle i32 %14, 127
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i32, i32* %6
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 0
store i8 %18, i8* %20
store i32 1, i32* %3
br label %35
21: ; preds = %13
%22 = load i32, i32* %6
%23 = ashr i32 %22, 6
%24 = and i32 %23, 31
%25 = add nsw i32 192, %24
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 %26, i8* %28
%29 = load i32, i32* %6
%30 = and i32 %29, 63
%31 = add nsw i32 128, %30
%32 = trunc i32 %31 to i8
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8 %32, i8* %34
store i32 2, i32* %3
br label %35
35: ; preds = %21, %16, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_latin1(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = tail call i32 @fgetc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp eq i32 %3, %4
br i1 %5, label %19, label %6
6: ; preds = %2
%7 = icmp slt i32 %3, 128
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = trunc i32 %3 to i8
store i8 %9, i8* %1
br label %19
10: ; preds = %6
%11 = lshr i32 %3, 6
%12 = trunc i32 %11 to i8
%13 = and i8 %12, 31
%14 = or i8 %13, -64
store i8 %14, i8* %1
%15 = trunc i32 %3 to i8
%16 = and i8 %15, 63
%17 = or i8 %16, -128
%18 = getelementptr inbounds i8, i8* %1, i64 1
store i8 %17, i8* %18
br label %19
19: ; preds = %2, %10, %8
%20 = phi i32 [ 1, %8 ], [ 2, %10 ], [ -1, %2 ]
ret i32 %20
}