#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 */
char *ft_strchr(char const *, char);
char *ft_strsub(char const *, int /*<<< orphan*/, int);
scalar_t__ is_useless(char const);
char *ft_strtrim(const char *s) {
  char *temp;
  while (is_useless(*s))
    s++;
  temp = ft_strchr(s, '\0') - 1;
  while (is_useless(*temp))
    temp--;
  return (ft_strsub(s, 0, temp - s + 1));
}


x86 assembly (clang, -O0):
<ft_strtrim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_useless@plt>
cmp    $0x0,%rax
je     1163 <ft_strtrim+0x33>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <ft_strtrim+0xc>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <ft_strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <is_useless@plt>
cmp    $0x0,%rax
je     119d <ft_strtrim+0x6d>
mov    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
jmp    1176 <ft_strtrim+0x46>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <ft_strsub@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_strtrim>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    -0x2(%rdi),%r15d
add    $0xffffffffffffffff,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x1(%r14),%edi
add    $0x1,%r14
call   1030 <is_useless@plt>
add    $0x1,%r15d
test   %rax,%rax
jne    1150 <ft_strtrim+0x20>
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <ft_strchr@plt>
mov    %rax,%rbx
mov    %ebx,%ebp
sub    %r15d,%ebp
add    $0xffffffffffffffff,%rbx
nopl   (%rax)
movsbl (%rbx),%edi
call   1030 <is_useless@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1180 <ft_strtrim+0x50>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <ft_strsub@plt>

LLVM IR (-O0):
define i8* @ft_strtrim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = call i64 @is_useless(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
br label %4
12: ; preds = %4
%13 = load i8*, i8** %2
%14 = call i8* @ft_strchr(i8* %13, i8 signext 0)
%15 = getelementptr inbounds i8, i8* %14, i64 -1
store i8* %15, i8** %3
br label %16
16: ; preds = %21, %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i64 @is_useless(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %3
br label %16
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i8*, i8** %3
%27 = load i8*, i8** %2
%28 = ptrtoint i8* %26 to i64
%29 = ptrtoint i8* %27 to i64
%30 = sub i64 %28, %29
%31 = add nsw i64 %30, 1
%32 = trunc i64 %31 to i32
%33 = call i8* @ft_strsub(i8* %25, i32 0, i32 %32)
ret i8* %33
}

LLVM IR (-O2):
define i8* @ft_strtrim(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @is_useless(i8 signext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2
%9 = tail call i8* @ft_strchr(i8* %3, i8 signext 0)
br label %10
10: ; preds = %10, %8
%11 = phi i8* [ %9, %8 ], [ %12, %10 ]
%12 = getelementptr inbounds i8, i8* %11, i64 -1
%13 = load i8, i8* %12
%14 = tail call i64 @is_useless(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = ptrtoint i8* %12 to i64
%18 = ptrtoint i8* %3 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
%21 = add i32 %20, 1
%22 = tail call i8* @ft_strsub(i8* %3, i32 0, i32 %21)
ret i8* %22
}