#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*/ free(char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ strcpy(char *, char *);
char *xStrDup(char *);
char *leftTrim(char *str) {
  char *t;
  int i = 0;
  while (isspace(str[i]))
    i++;
  t = xStrDup(&str[i]);
  strcpy(str, t);
  if (t) {
    free(t);
  }
  return str;
}


x86 assembly (clang, -O0):
<leftTrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     117c <leftTrim+0x3c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <leftTrim+0x13>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1040 <xStrDup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b1 <leftTrim+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<leftTrim>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
mov    $0xffffffffffffffff,%rbx
nop
movsbl 0x1(%r15,%rbx,1),%edi
call   1060 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1150 <leftTrim+0x10>
mov    %ebx,%edi
add    %r15,%rdi
call   1040 <xStrDup@plt>
mov    %rax,%r14
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcpy@plt>
test   %r14,%r14
je     1189 <leftTrim+0x49>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @leftTrim(i8* returned %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ %8, %2 ], [ 0, %1 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = tail call i64 @isspace(i8 signext %5)
%7 = icmp eq i64 %6, 0
%8 = add nuw i64 %3, 1
br i1 %7, label %9, label %2
9: ; preds = %2
%10 = and i64 %3, 4294967295
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i8* @xStrDup(i8* %11)
%13 = tail call i32 @strcpy(i8* %0, i8* %12)
%14 = icmp eq i8* %12, null
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @free(i8* %12)
br label %17
17: ; preds = %15, %9
ret i8* %0
}