#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__ isspace(char);
int /*<<< orphan*/ memmove(char *, char *, scalar_t__);
scalar_t__ strlen(char *);
char *RmLeadingSpaces(char *str) {
  char *obuf;
  if (str) {
    for (obuf = str; *obuf && isspace(*obuf); ++obuf)
      ;
    if (str != obuf)
      memmove(str, obuf, strlen(obuf) + 1);
  }
  return str;
}


x86 assembly (clang, -O0):
<RmLeadingSpaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e0 <RmLeadingSpaces+0xb0>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     117a <RmLeadingSpaces+0x4a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118a <RmLeadingSpaces+0x5a>
jmp    11a0 <RmLeadingSpaces+0x70>
jmp    118f <RmLeadingSpaces+0x5f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    114f <RmLeadingSpaces+0x1f>
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11db <RmLeadingSpaces+0xab>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1050 <memmove@plt>
jmp    11e0 <RmLeadingSpaces+0xb0>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RmLeadingSpaces>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     1185 <RmLeadingSpaces+0x55>
mov    (%r14),%al
test   %al,%al
je     1185 <RmLeadingSpaces+0x55>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1169 <RmLeadingSpaces+0x39>
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <RmLeadingSpaces+0x20>
cmp    %r14,%rbx
je     1185 <RmLeadingSpaces+0x55>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <memmove@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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