#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 */
scalar_t__ isspace(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strtriml(char *str) {
  int i = 0, j;
  j = strlen(str) - 1;
  while (isspace((int)str[i]) && (i <= j))
    i++;
  if (0 < i)
    strcpy(str, &str[i]);
  return str;
}


x86 assembly (clang, -O0):
<strtriml>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x11(%rbp)
je     1181 <strtriml+0x51>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
setle  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1191 <strtriml+0x61>
jmp    119f <strtriml+0x6f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <strtriml+0x22>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jge    11be <strtriml+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtriml>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%edi
call   1050 <isspace@plt>
lea    0x1(%rbx),%rcx
test   %rax,%rax
je     116b <strtriml+0x3b>
cmp    %r15,%rbx
mov    %rcx,%rbx
jl     1150 <strtriml+0x20>
cmp    $0x1,%ecx
je     1180 <strtriml+0x50>
lea    (%r14,%rcx,1),%rsi
add    $0xffffffffffffffff,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @strtriml(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %4
br label %8
8: ; preds = %23, %1
%9 = load i8*, i8** %2
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i64 @isspace(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %8
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = icmp sle i32 %18, %19
br label %21
21: ; preds = %17, %8
%22 = phi i1 [ false, %8 ], [ %20, %17 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %8
26: ; preds = %21
%27 = load i32, i32* %3
%28 = icmp slt i32 0, %27
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i8*, i8** %2
%31 = load i8*, i8** %2
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @strcpy(i8* %30, i8* %34)
br label %36
36: ; preds = %29, %26
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
define i8* @strtriml(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %13, %4 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = tail call i64 @isspace(i32 %8)
%10 = icmp ne i64 %9, 0
%11 = icmp slt i64 %5, %3
%12 = select i1 %10, i1 %11, i1 false
%13 = add nuw nsw i64 %5, 1
br i1 %12, label %4, label %14
14: ; preds = %4
%15 = trunc i64 %5 to i32
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = and i64 %5, 4294967295
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = tail call i32 @strcpy(i8* %0, i8* %19)
br label %21
21: ; preds = %17, %14
ret i8* %0
}