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


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 = %22, %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 = call i64 @isspace(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = load i32, i32* %3
%18 = load i32, i32* %4
%19 = icmp sle i32 %17, %18
br label %20
20: ; preds = %16, %8
%21 = phi i1 [ false, %8 ], [ %19, %16 ]
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %8
25: ; preds = %20
%26 = load i32, i32* %3
%27 = icmp slt i32 0, %26
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %2
%30 = load i8*, i8** %2
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i32 @strcpy(i8* %29, i8* %33)
br label %35
35: ; preds = %28, %25
%36 = load i8*, i8** %2
ret i8* %36
}

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 [ %12, %4 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i64 @isspace(i8 signext %7)
%9 = icmp ne i64 %8, 0
%10 = icmp slt i64 %5, %3
%11 = select i1 %9, i1 %10, i1 false
%12 = add nuw nsw i64 %5, 1
br i1 %11, label %4, label %13
13: ; preds = %4
%14 = trunc i64 %5 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = and i64 %5, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = tail call i32 @strcpy(i8* %0, i8* %18)
br label %20
20: ; preds = %16, %13
ret i8* %0
}