#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 strlen(char *);
int ws(char *);
char *ltrim(char *str) {
  int i;
  int spc = ws(str);
  if (spc == -1) {
    return "";
  }
  for (i = 0; i < strlen(str); i++) {
    str[i] = str[i + spc];
  }
  str[i] = 0;
  return str;
}


x86 assembly (clang, -O0):
<ltrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ws@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1152 <ltrim+0x32>
lea    0xeb7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b2 <ltrim+0x92>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    119e <ltrim+0x7e>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <ltrim+0x39>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ltrim>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1030 <ws@plt>
cmp    $0xffffffff,%eax
je     116d <ltrim+0x4d>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1176 <ltrim+0x56>
movslq %ebp,%r14
add    %rbx,%r14
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbp,1),%eax
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1150 <ltrim+0x30>
jmp    1178 <ltrim+0x58>
lea    0xe8c(%rip),%rbx
jmp    117c <ltrim+0x5c>
xor    %ebp,%ebp
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @ltrim(i8* %0) {
%2 = tail call i32 @ws(i8* %0)
%3 = icmp eq i32 %2, -1
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = sext i32 %2 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %15, %9 ]
%11 = add nsw i64 %10, %8
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %13, i8* %14
%15 = add nuw nsw i64 %10, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %9, label %19
19: ; preds = %9
%20 = and i64 %15, 4294967295
br label %21
21: ; preds = %19, %4
%22 = phi i64 [ 0, %4 ], [ %20, %19 ]
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %1, %21
%25 = phi i8* [ %0, %21 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %25
}