#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);
scalar_t__ n_assert_fail(char *, char *, int);
char *strchr(char *, char);
char *n_str_strip_ws(char *str) {
  char *p;
  if (str == NULL)
    return str;
  p = str;
  while (isspace(*p))
    p++;
  str = p;
  p = strchr(str, '\0');
  ((void)((p) ? 0
              : (n_assert_fail("p",
                               "/scratch/repos/new/home/jordi_armengol_estape/"
                               "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                               "megabajt/trurlib/refs/heads/master/nstr.c",
                               22),
                 0)));
  p--;
  while (p != str && isspace(*p)) {
    *p = '\0';
    p--;
  }
  return str;
}


x86 assembly (clang, -O0):
<n_str_strip_ws>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <n_str_strip_ws+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1227 <n_str_strip_ws+0xf7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1183 <n_str_strip_ws+0x53>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <n_str_strip_ws+0x2c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11aa <n_str_strip_ws+0x7a>
jmp    11c2 <n_str_strip_ws+0x92>
lea    0xe4f(%rip),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x16,%edx
call   1050 <n_assert_fail@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x19(%rbp)
je     11f7 <n_str_strip_ws+0xc7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1207 <n_str_strip_ws+0xd7>
jmp    121f <n_str_strip_ws+0xef>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11ce <n_str_strip_ws+0x9e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<n_str_strip_ws>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11ae <n_str_strip_ws+0x7e>
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isspace@plt>
test   %rax,%rax
jne    1140 <n_str_strip_ws+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%r14
mov    %rbx,%rax
add    %r14,%rax
jne    117d <n_str_strip_ws+0x4d>
lea    0xe94(%rip),%rdi
lea    0xe8f(%rip),%rsi
mov    $0x16,%edx
call   1050 <n_assert_fail@plt>
lea    (%rbx,%r14,1),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
je     11b0 <n_str_strip_ws+0x80>
add    $0xfffffffffffffffe,%r14
xchg   %ax,%ax
movsbl 0x1(%rbx,%r14,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11b0 <n_str_strip_ws+0x80>
movb   $0x0,0x1(%rbx,%r14,1)
add    $0xffffffffffffffff,%r14
jb     1190 <n_str_strip_ws+0x60>
jmp    11b0 <n_str_strip_ws+0x80>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"p\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/megabajt/trurlib/refs/heads/master/nstr.c\00"
define i8* @n_str_strip_ws(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i8*, i8** %3
store i8* %8, i8** %2
br label %49
9: ; preds = %1
%10 = load i8*, i8** %3
store i8* %10, i8** %4
br label %11
11: ; preds = %16, %9
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call i64 @isspace(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
br label %11
19: ; preds = %11
%20 = load i8*, i8** %4
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = call i8* @strchr(i8* %21, i8 signext 0)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %26
25: ; preds = %19
br label %28
26: ; preds = %19
%27 = call i64 @n_assert_fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 22)
br label %28
28: ; preds = %26, %25
%29 = phi i32 [ 0, %25 ], [ 0, %26 ]
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %4
br label %32
32: ; preds = %43, %28
%33 = load i8*, i8** %4
%34 = load i8*, i8** %3
%35 = icmp ne i8* %33, %34
br i1 %35, label %36, label %41
36: ; preds = %32
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = call i64 @isspace(i8 signext %38)
%40 = icmp ne i64 %39, 0
br label %41
41: ; preds = %36, %32
%42 = phi i1 [ false, %32 ], [ %40, %36 ]
br i1 %42, label %43, label %47
43: ; preds = %41
%44 = load i8*, i8** %4
store i8 0, i8* %44
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %4
br label %32
47: ; preds = %41
%48 = load i8*, i8** %3
store i8* %48, i8** %2
br label %49
49: ; preds = %47, %7
%50 = load i8*, i8** %2
ret i8* %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"p\00"
@.str.1 = [132 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/megabajt/trurlib/refs/heads/master/nstr.c\00"
define i8* @n_str_strip_ws(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %26, label %3
3: ; preds = %1, %3
%4 = phi i8* [ %8, %3 ], [ %0, %1 ]
%5 = load i8, i8* %4
%6 = tail call i64 @isspace(i8 signext %5)
%7 = icmp eq i64 %6, 0
%8 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = tail call i64 @strlen(i8* %4)
%11 = getelementptr i8, i8* %4, i64 %10
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = tail call i64 @n_assert_fail(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str.1, i64 0, i64 0), i32 22)
br label %15
15: ; preds = %9, %13
%16 = getelementptr inbounds i8, i8* %11, i64 -1
%17 = icmp eq i8* %16, %4
br i1 %17, label %26, label %18
18: ; preds = %15, %23
%19 = phi i8* [ %24, %23 ], [ %16, %15 ]
%20 = load i8, i8* %19
%21 = tail call i64 @isspace(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
store i8 0, i8* %19
%24 = getelementptr inbounds i8, i8* %19, i64 -1
%25 = icmp eq i8* %24, %4
br i1 %25, label %26, label %18
26: ; preds = %23, %18, %15, %1
%27 = phi i8* [ null, %1 ], [ %4, %15 ], [ %4, %18 ], [ %4, %23 ]
ret i8* %27
}