#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 hstr_chop(char *s) {
  if (s) {
    int i = strlen(s);
    if (i) {
      if (1 << 7 & s[i - 1]) {
        s[i - 2] = 0;
      } else {
        s[i - 1] = 0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<hstr_chop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     118d <hstr_chop+0x7d>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1188 <hstr_chop+0x78>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1172 <hstr_chop+0x62>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1183 <hstr_chop+0x73>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1188 <hstr_chop+0x78>
jmp    118d <hstr_chop+0x7d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hstr_chop>:
push   %rbx
test   %rdi,%rdi
je     113d <hstr_chop+0x2d>
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
je     113d <hstr_chop+0x2d>
cltq
lea    (%rax,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
cmpb   $0x0,-0x1(%rax,%rbx,1)
lea    -0x2(%rax,%rbx,1),%rax
cmovns %rcx,%rax
movb   $0x0,(%rax)
pop    %rbx
ret

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

LLVM IR (-O2):
define void @hstr_chop(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %3
%7 = add nsw i32 %4, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp sgt i8 %10, -1
%12 = add nsw i32 %4, -2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = select i1 %11, i8* %9, i8* %14
store i8 0, i8* %15
br label %16
16: ; preds = %6, %3, %1
ret void
}