#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 */
int strlen(char *);
void utf8_remove_last_char(char *utf8) {
  char *str_end;
  unsigned char char_erased;
  int erased_all_string;
  int single_byte_character;
  int first_byte_of_sequence;
  if (!utf8 || !(*utf8))
    return;
  str_end = utf8 + strlen(utf8) - 1;
  do {
    char_erased = *str_end;
    (*str_end--) = '\0';
    erased_all_string = (str_end < utf8);
    single_byte_character = (char_erased < 0x80);
    first_byte_of_sequence = (char_erased & 0x40);
  } while (!erased_all_string && !single_byte_character &&
           !first_byte_of_sequence);
}


x86 assembly (clang, -O0):
<utf8_remove_last_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1134 <utf8_remove_last_char+0x24>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1139 <utf8_remove_last_char+0x29>
jmp    11df <utf8_remove_last_char+0xcf>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x80,%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
movzbl -0x11(%rbp),%eax
and    $0x40,%eax
mov    %eax,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
jne    11d4 <utf8_remove_last_char+0xc4>
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x29(%rbp)
jne    11d4 <utf8_remove_last_char+0xc4>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    115e <utf8_remove_last_char+0x4e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<utf8_remove_last_char>:
push   %rbx
test   %rdi,%rdi
je     114c <utf8_remove_last_char+0x3c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     114c <utf8_remove_last_char+0x3c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xfffffffffffffffe,%rax
nop
movzbl 0x1(%rax),%ecx
movb   $0x0,0x1(%rax)
cmp    %rbx,%rax
jb     114c <utf8_remove_last_char+0x3c>
test   %cl,%cl
jns    114c <utf8_remove_last_char+0x3c>
and    $0x40,%cl
add    $0xffffffffffffffff,%rax
test   %cl,%cl
je     1130 <utf8_remove_last_char+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @utf8_remove_last_char(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %10, %1
br label %50
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8*, i8** %2
%18 = call i32 @strlen(i8* %17)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 -1
store i8* %21, i8** %3
br label %22
22: ; preds = %48, %15
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
store i8 %24, i8* %4
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i32 -1
store i8* %26, i8** %3
store i8 0, i8* %25
%27 = load i8*, i8** %3
%28 = load i8*, i8** %2
%29 = icmp ult i8* %27, %28
%30 = zext i1 %29 to i32
store i32 %30, i32* %5
%31 = load i8, i8* %4
%32 = zext i8 %31 to i32
%33 = icmp slt i32 %32, 128
%34 = zext i1 %33 to i32
store i32 %34, i32* %6
%35 = load i8, i8* %4
%36 = zext i8 %35 to i32
%37 = and i32 %36, 64
store i32 %37, i32* %7
br label %38
38: ; preds = %22
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 0
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = load i32, i32* %6
%43 = icmp ne i32 %42, 0
br i1 %43, label %48, label %44
44: ; preds = %41
%45 = load i32, i32* %7
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br label %48
48: ; preds = %44, %41, %38
%49 = phi i1 [ false, %41 ], [ false, %38 ], [ %47, %44 ]
br i1 %49, label %22, label %50
50: ; preds = %14, %48
ret void
}

LLVM IR (-O2):
define void @utf8_remove_last_char(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %21, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = getelementptr inbounds i8, i8* %9, i64 -1
br label %11
11: ; preds = %11, %6
%12 = phi i8* [ %10, %6 ], [ %14, %11 ]
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %12, i64 -1
store i8 0, i8* %12
%15 = icmp uge i8* %14, %0
%16 = icmp slt i8 %13, 0
%17 = and i8 %13, 64
%18 = select i1 %15, i1 %16, i1 false
%19 = icmp eq i8 %17, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %11, label %21
21: ; preds = %11, %1, %3
ret void
}