#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 */
scalar_t__ iTestStrZero(unsigned char *, scalar_t__);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, scalar_t__);
int /*<<< orphan*/ strcpy(unsigned char *, char *);
scalar_t__ strlen(unsigned char *);
void vTrimHead0(unsigned char *pszN) {
  if (iTestStrZero(pszN, strlen(pszN)) == 0) {
    strcpy(pszN, "0");
    return;
  }
  if (strlen(pszN) == 0) {
    strcpy(pszN, "0");
    return;
  }
  while (pszN[0] == '0') {
    memmove(pszN, pszN + 1, strlen(pszN));
  }
  if (strlen(pszN) == 0)
    strcpy(pszN, "0");
}


x86 assembly (clang, -O0):
<vTrimHead0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x10(%rbp),%rdi
mov    %rax,%rsi
call   1050 <iTestStrZero@plt>
cmp    $0x0,%rax
jne    1188 <vTrimHead0+0x48>
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1030 <strcpy@plt>
jmp    121a <vTrimHead0+0xda>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    11b0 <vTrimHead0+0x70>
mov    -0x8(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    121a <vTrimHead0+0xda>
jmp    11b5 <vTrimHead0+0x75>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
jne    11f7 <vTrimHead0+0xb7>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
call   1060 <memmove@plt>
jmp    11b5 <vTrimHead0+0x75>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jne    121a <vTrimHead0+0xda>
mov    -0x8(%rbp),%rdi
lea    0xdeb(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vTrimHead0>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <iTestStrZero@plt>
test   %rax,%rax
je     1191 <vTrimHead0+0x51>
mov    (%rbx),%al
test   %al,%al
je     1191 <vTrimHead0+0x51>
lea    0x1(%rbx),%r14
cmp    $0x30,%al
jne    118d <vTrimHead0+0x4d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1060 <memmove@plt>
movzbl (%rbx),%eax
cmp    $0x30,%al
je     1170 <vTrimHead0+0x30>
test   %al,%al
jne    11a7 <vTrimHead0+0x67>
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define void @vTrimHead0(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = load i8*, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
%6 = call i64 @iTestStrZero(i8* %3, i64 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %39
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i64 @strlen(i8* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %39
18: ; preds = %11
br label %19
19: ; preds = %25, %18
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp eq i32 %23, 48
br i1 %24, label %25, label %32
25: ; preds = %19
%26 = load i8*, i8** %2
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8*, i8** %2
%30 = call i64 @strlen(i8* %29)
%31 = call i32 @memmove(i8* %26, i8* %28, i64 %30)
br label %19
32: ; preds = %19
%33 = load i8*, i8** %2
%34 = call i64 @strlen(i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i8*, i8** %2
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %39
39: ; preds = %8, %15, %36, %32
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define void @vTrimHead0(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = tail call i64 @iTestStrZero(i8* %0, i64 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
7: ; preds = %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 1
br label %14
12: ; preds = %7
%13 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
14: ; preds = %10, %16
%15 = phi i8 [ %19, %16 ], [ %8, %10 ]
switch i8 %15, label %22 [
i8 48, label %16
i8 0, label %20
]
16: ; preds = %14
%17 = tail call i64 @strlen(i8* %0)
%18 = tail call i32 @memmove(i8* %0, i8* %11, i64 %17)
%19 = load i8, i8* %0
br label %14
20: ; preds = %14
%21 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %14, %5, %12, %20
ret void
}