#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*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int, int, char *);
int strlen(char *);
char *strltrim(char *s) {
  register const unsigned char *p;
  char c;
  int pos = 0;
  int left_len;
  char buff[1024] = "";
  if (s == NULL)
    return NULL;
  if (s[0] != ' ')
    return s;
  p = (const unsigned char *)s;
  while ((c = *p++)) {
    if (c == ' ')
      pos++;
    else
      break;
  }
  left_len = strlen(s) - pos;
  memcpy(s, s + pos, left_len);
  memcpy(buff, s + pos, left_len);
  printf("%d %d [%s]\n", pos, left_len, buff);
  return s;
}


x86 assembly (clang, -O0):
<strltrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x430(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1181 <strltrim+0x41>
movq   $0x0,-0x8(%rbp)
jmp    1248 <strltrim+0x108>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     119e <strltrim+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1248 <strltrim+0x108>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
cmp    $0x0,%al
je     11e7 <strltrim+0xa7>
movsbl -0x19(%rbp),%eax
cmp    $0x20,%eax
jne    11dd <strltrim+0x9d>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e2 <strltrim+0xa2>
jmp    11e7 <strltrim+0xa7>
jmp    11a6 <strltrim+0x66>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1060 <memcpy@plt>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    -0x430(%rbp),%rcx
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strltrim>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
test   %r14,%r14
je     11c3 <strltrim+0x83>
cmpb   $0x20,(%r14)
jne    11c3 <strltrim+0x83>
xor    %ebx,%ebx
xchg   %ax,%ax
cmpb   $0x20,0x1(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
je     1170 <strltrim+0x30>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r15d
sub    %ebx,%r15d
mov    %rbx,%rbp
add    %r14,%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
call   1060 <memcpy@plt>
lea    0xe4a(%rip),%rdi
mov    %ebx,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d %d [%s]\0A\00"
define i8* @strltrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
store i8* %0, i8** %3
store i32 0, i32* %6
%9 = bitcast [1024 x i8]* %8 to i8*
%10 = load i8*, i8** %3
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i8* null, i8** %2
br label %61
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 32
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i8*, i8** %3
store i8* %20, i8** %2
br label %61
21: ; preds = %13
%22 = load i8*, i8** %3
store i8* %22, i8** %4
br label %23
23: ; preds = %36, %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8, i8* %24
store i8 %26, i8* %5
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 32
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %36
35: ; preds = %28
br label %37
36: ; preds = %32
br label %23
37: ; preds = %35, %23
%38 = load i8*, i8** %3
%39 = call i32 @strlen(i8* %38)
%40 = load i32, i32* %6
%41 = sub nsw i32 %39, %40
store i32 %41, i32* %7
%42 = load i8*, i8** %3
%43 = load i8*, i8** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i32, i32* %7
%48 = call i32 @memcpy(i8* %42, i8* %46, i32 %47)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = load i8*, i8** %3
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i32, i32* %7
%55 = call i32 @memcpy(i8* %49, i8* %53, i32 %54)
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%59 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %56, i32 %57, i8* %58)
%60 = load i8*, i8** %3
store i8* %60, i8** %2
br label %61
61: ; preds = %37, %19, %12
%62 = load i8*, i8** %2
ret i8* %62
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d %d [%s]\0A\00"
define i8* @strltrim(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %23, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 32
br i1 %7, label %8, label %23
8: ; preds = %5, %8
%9 = phi i32 [ %12, %8 ], [ 0, %5 ]
%10 = phi i8* [ %11, %8 ], [ %0, %5 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = add nuw nsw i32 %9, 1
%13 = load i8, i8* %11
%14 = icmp eq i8 %13, 32
br i1 %14, label %8, label %15
15: ; preds = %8
%16 = tail call i32 @strlen(i8* %0)
%17 = sub nsw i32 %16, %12
%18 = zext i32 %12 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i32 @memcpy(i8* %0, i8* %19, i32 %17)
%21 = call i32 @memcpy(i8* %3, i8* %19, i32 %17)
%22 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %17, i8* %3)
br label %23
23: ; preds = %5, %1, %15
ret i8* %0
}