#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 */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void trim_leading(char *buf) {
  int i, len = strlen(buf);
  char *tmpbuf = calloc(len + 1, 1);
  for (i = 0; i < len; i++) {
    if (buf[i] != ' ' && buf[i] != '\t')
      break;
  }
  strcpy(tmpbuf, buf + i);
  strcpy(buf, tmpbuf);
  free(tmpbuf);
}


x86 assembly (clang, -O0):
<trim_leading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11c1 <trim_leading+0x81>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     11ae <trim_leading+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     11ae <trim_leading+0x6e>
jmp    11c1 <trim_leading+0x81>
jmp    11b3 <trim_leading+0x73>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1173 <trim_leading+0x33>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_leading>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%r15d
lea    0x1(%r15),%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
test   %r15d,%r15d
jle    1189 <trim_leading+0x49>
mov    %r15d,%ecx
xor    %eax,%eax
jmp    1179 <trim_leading+0x39>
nopl   (%rax)
add    $0x1,%rax
cmp    %rax,%rcx
je     118d <trim_leading+0x4d>
movzbl (%rbx,%rax,1),%edx
cmp    $0x20,%dl
je     1170 <trim_leading+0x30>
cmp    $0x9,%dl
je     1170 <trim_leading+0x30>
jmp    118f <trim_leading+0x4f>
xor    %eax,%eax
jmp    118f <trim_leading+0x4f>
mov    %ecx,%eax
mov    %eax,%esi
add    %rbx,%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

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

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