#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__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void remove_leading_whitespace(char *buffer) {
  char *buffer2 = NULL;
  int i = 0, j = 0, ews = 0;
  buffer2 = (char *)malloc(strlen(buffer) * sizeof(char));
  if (buffer2 == NULL)
    return;
  memset(buffer2, (char)0, strlen(buffer));
  while (i < strlen(buffer)) {
    if (!(buffer[i] == (char)32 || buffer[i] == (char)9) || ews == 1) {
      ews = 1;
      buffer2[j] = buffer[i];
      j++;
    }
    i++;
  }
  memset(buffer, (char)0, strlen(buffer));
  strcpy(buffer, buffer2);
  free(buffer2);
}


x86 assembly (clang, -O0):
<remove_leading_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a3 <remove_leading_whitespace+0x53>
jmp    1279 <remove_leading_whitespace+0x129>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    1245 <remove_leading_whitespace+0xf5>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1207 <remove_leading_whitespace+0xb7>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
jne    1211 <remove_leading_whitespace+0xc1>
cmpl   $0x1,-0x1c(%rbp)
jne    1237 <remove_leading_whitespace+0xe7>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c1 <remove_leading_whitespace+0x71>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_leading_whitespace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1050 <strlen@plt>
mov    %eax,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     1223 <remove_leading_whitespace+0xd3>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %r13d,%r13d
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11ee <remove_leading_whitespace+0x9e>
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    11c6 <remove_leading_whitespace+0x76>
movslq %r12d,%r12
mov    %al,(%r14,%r12,1)
add    $0x1,%r12d
mov    $0x1,%ebp
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
mov    %ebp,%r13d
cmp    %rax,%rbx
jge    11ee <remove_leading_whitespace+0x9e>
movzbl (%r15,%rbx,1),%eax
cmp    $0x20,%al
jne    11e0 <remove_leading_whitespace+0x90>
xor    %ebp,%ebp
cmp    $0x1,%r13d
je     11a0 <remove_leading_whitespace+0x50>
jmp    11b0 <remove_leading_whitespace+0x60>
nopl   0x0(%rax)
cmp    $0x1,%r13d
je     11a0 <remove_leading_whitespace+0x50>
xor    %ebp,%ebp
cmp    $0x9,%al
je     11b0 <remove_leading_whitespace+0x60>
jmp    11a0 <remove_leading_whitespace+0x50>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @remove_leading_whitespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 1
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %1
br label %71
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i8*, i8** %2
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @memset(i8* %18, i8 signext 0, i32 %20)
br label %22
22: ; preds = %58, %17
%23 = load i32, i32* %4
%24 = load i8*, i8** %2
%25 = call i32 @strlen(i8* %24)
%26 = icmp slt i32 %23, %25
br i1 %26, label %27, label %61
27: ; preds = %22
%28 = load i8*, i8** %2
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 32
br i1 %34, label %43, label %35
35: ; preds = %27
%36 = load i8*, i8** %2
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 9
br i1 %42, label %43, label %46
43: ; preds = %35, %27
%44 = load i32, i32* %6
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %58
46: ; preds = %43, %35
store i32 1, i32* %6
%47 = load i8*, i8** %2
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = load i8, i8* %50
%52 = load i8*, i8** %3
%53 = load i32, i32* %5
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
store i8 %51, i8* %55
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %58
58: ; preds = %46, %43
%59 = load i32, i32* %4
%60 = add nsw i32 %59, 1
store i32 %60, i32* %4
br label %22
61: ; preds = %22
%62 = load i8*, i8** %2
%63 = load i8*, i8** %2
%64 = call i32 @strlen(i8* %63)
%65 = call i32 @memset(i8* %62, i8 signext 0, i32 %64)
%66 = load i8*, i8** %2
%67 = load i8*, i8** %3
%68 = call i32 @strcpy(i8* %66, i8* %67)
%69 = load i8*, i8** %3
%70 = call i32 @free(i8* %69)
br label %71
71: ; preds = %61, %16
ret void
}

LLVM IR (-O2):
define void @remove_leading_whitespace(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %40, label %6
6: ; preds = %1
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @memset(i8* %4, i8 signext 0, i32 %7)
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %6, %28
%12 = phi i64 [ %31, %28 ], [ 0, %6 ]
%13 = phi i32 [ %30, %28 ], [ 0, %6 ]
%14 = phi i32 [ %29, %28 ], [ 0, %6 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %12
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 32
br i1 %17, label %22, label %18
18: ; preds = %11
%19 = icmp ne i8 %16, 9
%20 = icmp eq i32 %13, 1
%21 = or i1 %20, %19
br i1 %21, label %24, label %28
22: ; preds = %11
%23 = icmp eq i32 %13, 1
br i1 %23, label %24, label %28
24: ; preds = %22, %18
%25 = sext i32 %14 to i64
%26 = getelementptr inbounds i8, i8* %4, i64 %25
store i8 %16, i8* %26
%27 = add nsw i32 %14, 1
br label %28
28: ; preds = %18, %24, %22
%29 = phi i32 [ %27, %24 ], [ %14, %22 ], [ %14, %18 ]
%30 = phi i32 [ 1, %24 ], [ 0, %22 ], [ 0, %18 ]
%31 = add nuw nsw i64 %12, 1
%32 = tail call i32 @strlen(i8* %0)
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %11, label %35
35: ; preds = %28, %6
%36 = tail call i32 @strlen(i8* %0)
%37 = tail call i32 @memset(i8* %0, i8 signext 0, i32 %36)
%38 = tail call i32 @strcpy(i8* %0, i8* %4)
%39 = tail call i32 @free(i8* %4)
br label %40
40: ; preds = %1, %35
ret void
}