#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*/ memmove(char *, char *, int);
int strlen(char *);
void strip_leading_zeros(char *buffer) {
  int length;
  int i;
  length = strlen(buffer);
  for (i = 0; i < length; i++) {
    if (buffer[i] != '0')
      break;
  }
  if (i == length) {
    buffer[1] = '\0';
  } else {
    memmove(&buffer[0], &buffer[i], sizeof(char) * (length - i + 1));
  }
  return;
}


x86 assembly (clang, -O0):
<strip_leading_zeros>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1178 <strip_leading_zeros+0x58>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
je     1165 <strip_leading_zeros+0x45>
jmp    1178 <strip_leading_zeros+0x58>
jmp    116a <strip_leading_zeros+0x4a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113f <strip_leading_zeros+0x1f>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    1191 <strip_leading_zeros+0x71>
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    11b6 <strip_leading_zeros+0x96>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1040 <memmove@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_leading_zeros>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1151 <strip_leading_zeros+0x31>
mov    %eax,%edx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmpb   $0x30,(%rbx,%rcx,1)
jne    1153 <strip_leading_zeros+0x33>
add    $0x1,%rcx
cmp    %rcx,%rdx
jne    1140 <strip_leading_zeros+0x20>
jmp    1157 <strip_leading_zeros+0x37>
xor    %ecx,%ecx
sub    %ecx,%eax
jne    115d <strip_leading_zeros+0x3d>
movb   $0x0,0x1(%rbx)
pop    %rbx
ret
mov    %ecx,%esi
add    %rbx,%rsi
add    $0x1,%eax
mov    %rbx,%rdi
mov    %eax,%edx
pop    %rbx
jmp    1040 <memmove@plt>

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

LLVM IR (-O2):
define void @strip_leading_zeros(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %11
%7 = phi i64 [ 0, %4 ], [ %12, %11 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 48
br i1 %10, label %11, label %14
11: ; preds = %6
%12 = add nuw nsw i64 %7, 1
%13 = icmp eq i64 %12, %5
br i1 %13, label %19, label %6
14: ; preds = %6
%15 = trunc i64 %7 to i32
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 0, %1 ], [ %15, %14 ]
%18 = icmp eq i32 %2, %17
br i1 %18, label %19, label %21
19: ; preds = %11, %16
%20 = getelementptr inbounds i8, i8* %0, i64 1
store i8 0, i8* %20
br label %27
21: ; preds = %16
%22 = zext i32 %17 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = add i32 %2, 1
%25 = sub i32 %24, %17
%26 = tail call i32 @memmove(i8* %0, i8* %23, i32 %25)
br label %27
27: ; preds = %21, %19
ret void
}