#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char *malloc_err(size_t);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *RemoveLeadingZeroes(char *str) {
  unsigned int ctr = 0;
  char *temp = NULL;
  size_t size = 0;
  (assert(str != NULL));
  if (str[0] != '\0')
    while (1) {
      if ((str[ctr] == '0') && (str[ctr + 1] != '\0'))
        ctr++;
      else
        break;
    }
  size = strlen(&(str[ctr]));
  temp = malloc_err(size + 1);
  strcpy(temp, &(str[ctr]));
  return temp;
}


x86 assembly (clang, -O0):
<RemoveLeadingZeroes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d4 <RemoveLeadingZeroes+0x94>
jmp    118a <RemoveLeadingZeroes+0x4a>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jne    11c5 <RemoveLeadingZeroes+0x85>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11c5 <RemoveLeadingZeroes+0x85>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11ca <RemoveLeadingZeroes+0x8a>
jmp    11cf <RemoveLeadingZeroes+0x8f>
jmp    118a <RemoveLeadingZeroes+0x4a>
jmp    11d4 <RemoveLeadingZeroes+0x94>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%eax
add    %rax,%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc_err@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RemoveLeadingZeroes>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    (%rbx),%cl
test   %cl,%cl
je     1174 <RemoveLeadingZeroes+0x34>
xor    %edx,%edx
nopl   (%rax)
mov    %edx,%eax
cmp    $0x30,%cl
jne    1176 <RemoveLeadingZeroes+0x36>
lea    0x1(%rax),%edx
movzbl (%rbx,%rdx,1),%ecx
test   %cl,%cl
jne    1160 <RemoveLeadingZeroes+0x20>
jmp    1176 <RemoveLeadingZeroes+0x36>
xor    %eax,%eax
mov    %eax,%eax
add    %rax,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1060 <malloc_err@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @RemoveLeadingZeroes(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i32 0, i32* %3
store i8* null, i8** %4
store i64 0, i64* %5
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %39
15: ; preds = %1
br label %16
16: ; preds = %15, %37
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 48
br i1 %23, label %24, label %36
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i32, i32* %3
%27 = add i32 %26, 1
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* %3
%35 = add i32 %34, 1
store i32 %35, i32* %3
br label %37
36: ; preds = %24, %16
br label %38
37: ; preds = %33
br label %16
38: ; preds = %36
br label %39
39: ; preds = %38, %1
%40 = load i8*, i8** %2
%41 = load i32, i32* %3
%42 = zext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = call i64 @strlen(i8* %43)
store i64 %44, i64* %5
%45 = load i64, i64* %5
%46 = add i64 %45, 1
%47 = call i8* @malloc_err(i64 %46)
store i8* %47, i8** %4
%48 = load i8*, i8** %4
%49 = load i8*, i8** %2
%50 = load i32, i32* %3
%51 = zext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = call i32 @strcpy(i8* %48, i8* %52)
%54 = load i8*, i8** %4
ret i8* %54
}

LLVM IR (-O2):
define i8* @RemoveLeadingZeroes(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %1, %11
%8 = phi i8 [ %15, %11 ], [ %5, %1 ]
%9 = phi i32 [ %12, %11 ], [ 0, %1 ]
%10 = icmp eq i8 %8, 48
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = add i32 %9, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %11, %7, %1
%18 = phi i32 [ 0, %1 ], [ %9, %7 ], [ %9, %11 ]
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = tail call i64 @strlen(i8* %20)
%22 = add i64 %21, 1
%23 = tail call i8* @malloc_err(i64 %22)
%24 = tail call i32 @strcpy(i8* %23, i8* %20)
ret i8* %23
}