#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 *);
char *Misc_Str_CutHZString(char *sSrc) {
  int iLength;
  int i = 1;
  unsigned char *pcSrc = (unsigned char *)sSrc;
  iLength = strlen(sSrc);
  while (*pcSrc) {
    if (*pcSrc > 127 && i < iLength) {
      pcSrc += 2;
      i += 2;
    } else if (*pcSrc <= 127) {
      pcSrc++;
      i++;
    } else {
      *pcSrc = 0;
    }
  }
  return sSrc;
}


x86 assembly (clang, -O0):
<Misc_Str_CutHZString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b5 <Misc_Str_CutHZString+0xa5>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jle    117a <Misc_Str_CutHZString+0x6a>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117a <Misc_Str_CutHZString+0x6a>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    11b0 <Misc_Str_CutHZString+0xa0>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x7f,%eax
jg     11a4 <Misc_Str_CutHZString+0x94>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ab <Misc_Str_CutHZString+0x9b>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11b0 <Misc_Str_CutHZString+0xa0>
jmp    1137 <Misc_Str_CutHZString+0x27>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Misc_Str_CutHZString>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    (%r14),%bl
test   %bl,%bl
je     1162 <Misc_Str_CutHZString+0x52>
mov    $0x1,%ecx
mov    %r14,%rdx
jmp    1147 <Misc_Str_CutHZString+0x37>
nopl   (%rax)
mov    $0x2,%esi
mov    $0x2,%edi
movzbl (%rdx,%rdi,1),%ebx
add    %rdi,%rdx
add    %esi,%ecx
test   %bl,%bl
je     1162 <Misc_Str_CutHZString+0x52>
test   %bl,%bl
jns    114f <Misc_Str_CutHZString+0x3f>
cmp    %eax,%ecx
jl     1130 <Misc_Str_CutHZString+0x20>
test   %bl,%bl
js     115f <Misc_Str_CutHZString+0x4f>
mov    $0x1,%esi
mov    $0x1,%edi
jmp    113a <Misc_Str_CutHZString+0x2a>
movb   $0x0,(%rdx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @Misc_Str_CutHZString(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %5
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %40, %1
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = icmp sgt i32 %16, 127
br i1 %17, label %18, label %27
18: ; preds = %13
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2
store i8* %24, i8** %5
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 2
store i32 %26, i32* %4
br label %40
27: ; preds = %18, %13
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp sle i32 %30, 127
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %39
37: ; preds = %27
%38 = load i8*, i8** %5
store i8 0, i8* %38
br label %39
39: ; preds = %37, %32
br label %40
40: ; preds = %39, %22
br label %9
41: ; preds = %9
%42 = load i8*, i8** %2
ret i8* %42
}

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