#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(unsigned char);
int /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
void trim_line(char *line) {
  int len;
  char *fnw = line;
  while (isspace((unsigned char)*fnw))
    ++fnw;
  len = strlen(fnw);
  memmove(line, fnw, len);
  fnw = line + len - 1;
  while (fnw >= line && isspace((unsigned char)*fnw))
    *fnw-- = '\0';
}


x86 assembly (clang, -O0):
<trim_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     116b <trim_line+0x3b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <trim_line+0x14>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memmove@plt>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x8(%rbp),%rcx
mov    %al,-0x19(%rbp)
jb     11c3 <trim_line+0x93>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11d3 <trim_line+0xa3>
jmp    11ea <trim_line+0xba>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    119a <trim_line+0x6a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    -0x1(%rdi),%rbx
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <trim_line+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
movslq %ebp,%rax
lea    (%r14,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jb     1199 <trim_line+0x69>
nopl   0x0(%rax)
movzbl (%rbx),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1199 <trim_line+0x69>
movb   $0x0,(%rbx)
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jae    1180 <trim_line+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @trim_line(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 @isspace(i8 zeroext %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 i32 @strlen(i8* %3)
%10 = tail call i32 @memmove(i8* %0, i8* %3, i32 %9)
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %23, label %15
15: ; preds = %8, %20
%16 = phi i8* [ %21, %20 ], [ %13, %8 ]
%17 = load i8, i8* %16
%18 = tail call i64 @isspace(i8 zeroext %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
store i8 0, i8* %16
%21 = getelementptr inbounds i8, i8* %16, i64 -1
%22 = icmp ult i8* %21, %0
br i1 %22, label %23, label %15
23: ; preds = %15, %20, %8
ret void
}