#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char const *);
int strcspn(char const *, char *);
size_t strlen(char const *);
const char *trimSpaceL(const char *strval, char *buf, size_t bufsz) {
  int pos = 0;
  size_t inLen = 0;
  if (!strval) {
    printf("\x1B[31mBad call, NULL input string.\x1B[0m\n");
    return NULL;
  } else if (!buf) {
    printf("\x1B[31mBad call, NULL output buffer.\x1B[0m\n");
    return NULL;
  } else if ((inLen = strlen(strval)) > bufsz) {
    printf("\x1B[31mBad call, Output buffer is smaller then the input "
           "string.\x1B[0m\n");
    return NULL;
  } else {
    memset(buf, 0, sizeof(char) * bufsz);
    pos = strcspn(strval, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY"
                          "0123456789.,/<>?;:'\"[]{}=+-_()*&^%$#@!~`");
    if (pos >= 0) {
      printf("\x1B[33mDBG:\x1B[0m Got pos [%d], char at pos [%c]\n", pos,
             strval[pos]);
      strcpy(buf, strval + pos);
    }
    return buf;
  }
}


x86 assembly (clang, -O0):
<trimSpaceL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <trimSpaceL+0x49>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125c <trimSpaceL+0x10c>
cmpq   $0x0,-0x18(%rbp)
jne    11bf <trimSpaceL+0x6f>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125c <trimSpaceL+0x10c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
cmp    -0x20(%rbp),%rax
jbe    11f1 <trimSpaceL+0xa1>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    125c <trimSpaceL+0x10c>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <strcspn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1254 <trimSpaceL+0x104>
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trimSpaceL>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     118b <trimSpaceL+0x2b>
mov    %rsi,%r14
test   %rsi,%rsi
je     1194 <trimSpaceL+0x34>
mov    %rdx,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
cmp    %r15,%rax
jbe    11ac <trimSpaceL+0x4c>
lea    0xf4f(%rip),%rdi
jmp    119b <trimSpaceL+0x3b>
lea    0xef9(%rip),%rdi
jmp    119b <trimSpaceL+0x3b>
lea    0xf16(%rip),%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1070 <memset@plt>
lea    0xe40(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcspn@plt>
test   %eax,%eax
js     11a3 <trimSpaceL+0x43>
mov    %eax,%ecx
lea    (%rbx,%rcx,1),%r15
movsbl (%rbx,%rcx,1),%edx
lea    0xe80(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    11a3 <trimSpaceL+0x43>

LLVM IR (-O0):
@.str = [39 x i8] c"\1B[31mBad call, NULL input string.\1B[0m\0A\00"
@.str.1 = [40 x i8] c"\1B[31mBad call, NULL output buffer.\1B[0m\0A\00"
@.str.2 = [68 x i8] c"\1B[31mBad call, Output buffer is smaller then the input string.\1B[0m\0A\00"
@.str.3 = [93 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789.,/<>?;:'\22[]{}=+-_()*&^%$#@!~`\00"
@.str.4 = [46 x i8] c"\1B[33mDBG:\1B[0m Got pos [%d], char at pos [%c]\0A\00"
define i8* @trimSpaceL(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 0, i32* %8
store i64 0, i64* %9
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %4
br label %53
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %4
br label %53
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i64 @strlen(i8* %20)
store i64 %21, i64* %9
%22 = load i64, i64* %7
%23 = icmp ugt i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %4
br label %53
26: ; preds = %19
%27 = load i8*, i8** %6
%28 = load i64, i64* %7
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i32 @memset(i8* %27, i32 0, i32 %30)
%32 = load i8*, i8** %5
%33 = call i32 @strcspn(i8* %32, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.3, i64 0, i64 0))
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = icmp sge i32 %34, 0
br i1 %35, label %36, label %51
36: ; preds = %26
%37 = load i32, i32* %8
%38 = load i8*, i8** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32 %43)
%45 = load i8*, i8** %6
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = call i32 @strcpy(i8* %45, i8* %49)
br label %51
51: ; preds = %36, %26
%52 = load i8*, i8** %6
store i8* %52, i8** %4
br label %53
53: ; preds = %51, %24, %17, %12
%54 = load i8*, i8** %4
ret i8* %54
}

LLVM IR (-O2):
@.str.3 = [93 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY0123456789.,/<>?;:'\22[]{}=+-_()*&^%$#@!~`\00"
@.str.4 = [46 x i8] c"\1B[33mDBG:\1B[0m Got pos [%d], char at pos [%c]\0A\00"
@str = [38 x i8] c"\1B[31mBad call, NULL input string.\1B[0m\00"
@str.5 = [39 x i8] c"\1B[31mBad call, NULL output buffer.\1B[0m\00"
@str.6 = [67 x i8] c"\1B[31mBad call, Output buffer is smaller then the input string.\1B[0m\00"
define i8* @trimSpaceL(i8* %0, i8* %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %28
7: ; preds = %3
%8 = icmp eq i8* %1, null
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.5, i64 0, i64 0))
br label %28
11: ; preds = %7
%12 = tail call i64 @strlen(i8* %0)
%13 = icmp ugt i64 %12, %2
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.6, i64 0, i64 0))
br label %28
16: ; preds = %11
%17 = trunc i64 %2 to i32
%18 = tail call i32 @memset(i8* %1, i32 0, i32 %17)
%19 = tail call i32 @strcspn(i8* %0, i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp sgt i32 %19, -1
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = zext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i32 %19, i32 %25)
%27 = tail call i32 @strcpy(i8* %1, i8* %23)
br label %28
28: ; preds = %16, %21, %14, %9, %5
%29 = phi i8* [ null, %14 ], [ null, %9 ], [ null, %5 ], [ %1, %21 ], [ %1, %16 ]
ret i8* %29
}