#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 next_utf8(char const **, size_t *);
size_t strlen(char const *);
void charset_conv_utf8_to_iso_8859_1(char *iso, const char *utf8) {
  const char *utf8cur = utf8;
  size_t utf8len = strlen(utf8);
  unsigned char *isocur = iso;
  while (utf8len) {
    unsigned int nextpt = next_utf8(&utf8cur, &utf8len);
    if (nextpt == 0) {
      break;
    } else if (nextpt < 0x100) {
      *isocur = nextpt;
      ++isocur;
    }
  }
  *isocur = '\0';
}


x86 assembly (clang, -O0):
<charset_conv_utf8_to_iso_8859_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a5 <charset_conv_utf8_to_iso_8859_1+0x85>
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <next_utf8@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1177 <charset_conv_utf8_to_iso_8859_1+0x57>
jmp    11a5 <charset_conv_utf8_to_iso_8859_1+0x85>
cmpl   $0x100,-0x2c(%rbp)
jae    119b <charset_conv_utf8_to_iso_8859_1+0x7b>
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11a0 <charset_conv_utf8_to_iso_8859_1+0x80>
jmp    114d <charset_conv_utf8_to_iso_8859_1+0x2d>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charset_conv_utf8_to_iso_8859_1>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsi,0x8(%rsp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     1175 <charset_conv_utf8_to_iso_8859_1+0x55>
lea    0x8(%rsp),%r14
mov    %rsp,%r15
jmp    1157 <charset_conv_utf8_to_iso_8859_1+0x37>
nopl   0x0(%rax)
cmpq   $0x0,(%rsp)
je     1175 <charset_conv_utf8_to_iso_8859_1+0x55>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <next_utf8@plt>
test   %eax,%eax
je     1175 <charset_conv_utf8_to_iso_8859_1+0x55>
cmp    $0xff,%eax
ja     1150 <charset_conv_utf8_to_iso_8859_1+0x30>
mov    %al,(%rbx)
add    $0x1,%rbx
jmp    1150 <charset_conv_utf8_to_iso_8859_1+0x30>
movb   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @charset_conv_utf8_to_iso_8859_1(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
store i8* %9, i8** %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %6
%12 = load i8*, i8** %3
store i8* %12, i8** %7
br label %13
13: ; preds = %31, %2
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = call i32 @next_utf8(i8** %5, i64* %6)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %32
21: ; preds = %16
%22 = load i32, i32* %8
%23 = icmp ult i32 %22, 256
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* %8
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %7
store i8 %26, i8* %27
%28 = load i8*, i8** %7
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %7
br label %30
30: ; preds = %24, %21
br label %31
31: ; preds = %30
br label %13
32: ; preds = %20, %13
%33 = load i8*, i8** %7
store i8 0, i8* %33
ret void
}

LLVM IR (-O2):
define void @charset_conv_utf8_to_iso_8859_1(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* %1, i8** %3
%6 = bitcast i64* %4 to i8*
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
store i64 %7, i64* %4
%8 = icmp eq i64 %7, 0
br i1 %8, label %22, label %13
9: ; preds = %17, %19
%10 = phi i8* [ %14, %17 ], [ %21, %19 ]
%11 = load i64, i64* %4
%12 = icmp eq i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %2, %9
%14 = phi i8* [ %10, %9 ], [ %0, %2 ]
%15 = call i32 @next_utf8(i8** %3, i64* %4)
%16 = icmp eq i32 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = icmp ult i32 %15, 256
br i1 %18, label %19, label %9
19: ; preds = %17
%20 = trunc i32 %15 to i8
store i8 %20, i8* %14
%21 = getelementptr inbounds i8, i8* %14, i64 1
br label %9
22: ; preds = %9, %13, %2
%23 = phi i8* [ %0, %2 ], [ %14, %13 ], [ %10, %9 ]
store i8 0, i8* %23
ret void
}