#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*/ memmove(char *, char *, size_t);
int strlen(char *);
char *qstrtrim_head(char *str) {
  if (str == NULL)
    return NULL;
  char *ss;
  for (ss = str; *ss == ' ' || *ss == '\t' || *ss == '\r' || *ss == '\n'; ss++)
    ;
  if (ss > str) {
    size_t len = strlen(ss) + 1;
    memmove(str, ss, len);
  }
  return str;
}


x86 assembly (clang, -O0):
<qstrtrim_head>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <qstrtrim_head+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11fa <qstrtrim_head+0xda>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0x21(%rbp)
je     119b <qstrtrim_head+0x7b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0x21(%rbp)
je     119b <qstrtrim_head+0x7b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xd,%ecx
mov    %al,-0x21(%rbp)
je     119b <qstrtrim_head+0x7b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11ab <qstrtrim_head+0x8b>
jmp    11c1 <qstrtrim_head+0xa1>
jmp    11b0 <qstrtrim_head+0x90>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114c <qstrtrim_head+0x2c>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jbe    11f2 <qstrtrim_head+0xd2>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memmove@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qstrtrim_head>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     1173 <qstrtrim_head+0x53>
movabs $0x100002600,%rax
mov    %r14,%rbx
nopl   0x0(%rax)
movzbl (%rbx),%ecx
cmp    $0x20,%rcx
ja     1155 <qstrtrim_head+0x35>
bt     %rcx,%rax
jae    1155 <qstrtrim_head+0x35>
add    $0x1,%rbx
jmp    1140 <qstrtrim_head+0x20>
cmp    %r14,%rbx
jbe    1173 <qstrtrim_head+0x53>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <memmove@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @qstrtrim_head(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %52
9: ; preds = %1
%10 = load i8*, i8** %3
store i8* %10, i8** %4
br label %11
11: ; preds = %34, %9
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 32
br i1 %15, label %31, label %16
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 9
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 13
br i1 %25, label %31, label %26
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 10
br label %31
31: ; preds = %26, %21, %16, %11
%32 = phi i1 [ true, %21 ], [ true, %16 ], [ true, %11 ], [ %30, %26 ]
br i1 %32, label %33, label %37
33: ; preds = %31
br label %34
34: ; preds = %33
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
br label %11
37: ; preds = %31
%38 = load i8*, i8** %4
%39 = load i8*, i8** %3
%40 = icmp ugt i8* %38, %39
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = call i32 @strlen(i8* %42)
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
store i64 %45, i64* %5
%46 = load i8*, i8** %3
%47 = load i8*, i8** %4
%48 = load i64, i64* %5
%49 = call i32 @memmove(i8* %46, i8* %47, i64 %48)
br label %50
50: ; preds = %41, %37
%51 = load i8*, i8** %3
store i8* %51, i8** %2
br label %52
52: ; preds = %50, %8
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
define i8* @qstrtrim_head(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1, %6
%4 = phi i8* [ %7, %6 ], [ %0, %1 ]
%5 = load i8, i8* %4
switch i8 %5, label %8 [
i8 32, label %6
i8 9, label %6
i8 13, label %6
i8 10, label %6
]
6: ; preds = %3, %3, %3, %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
8: ; preds = %3
%9 = icmp ugt i8* %4, %0
br i1 %9, label %10, label %15
10: ; preds = %8
%11 = tail call i32 @strlen(i8* %4)
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = tail call i32 @memmove(i8* %0, i8* %4, i64 %13)
br label %15
15: ; preds = %8, %10, %1
ret i8* %0
}