int _remove_trailing_whitespace(char *buf, int buflen) {
  char *temp;
  if (!buf) {
    do {
      char __err[8192];
      int __len;
      memset(__err, '\0', 8192);
      __len =
          snprintf(__err, 8192, "(%s, %s, %d): ",
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/chaos/whatsup/refs/heads/"
                   "master/src/pingd/pingd_clusterlist_hostsfile.c",
                   __FUNCTION__, 166);
      if (__len < 8192) {
        char *__str;
        if ((__str = _debug_msg_create("invalid parameters"))) {
          strncat(__err, __str, 8192 - __len - 1);
          __len += strlen(__str);
          free(__str);
        }
      }
      err_debug(__err);
    } while (0);
    return -1;
  }
  temp = buf + buflen;
  for (--temp; temp >= buf; temp--) {
    if (isspace(*temp))
      *temp = '\0';
    else
      break;
    buflen--;
  }
  return buflen;
}


x86 assembly (clang, -O0):
<_remove_trailing_whitespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1288 <_remove_trailing_whitespace+0x108>
jmp    11a2 <_remove_trailing_whitespace+0x22>
lea    -0x2020(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
lea    -0x2020(%rbp),%rdi
mov    $0x2000,%esi
lea    0xe38(%rip),%rdx
lea    0xe40(%rip),%rcx
lea    0xedb(%rip),%r8
mov    $0xa6,%r9d
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x2000,-0x2024(%rbp)
jge    126e <_remove_trailing_whitespace+0xee>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   10a0 <_debug_msg_create@plt>
cltq
mov    %rax,-0x2030(%rbp)
cmp    $0x0,%rax
je     1269 <_remove_trailing_whitespace+0xe9>
lea    -0x2020(%rbp),%rdi
mov    -0x2030(%rbp),%rsi
mov    $0x2000,%eax
sub    -0x2024(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rdx
call   1080 <strncat@plt>
mov    -0x2030(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0x2024(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x2024(%rbp)
mov    -0x2030(%rbp),%rdi
call   1030 <free@plt>
jmp    126e <_remove_trailing_whitespace+0xee>
lea    -0x2020(%rbp),%rdi
mov    $0x0,%al
call   1070 <err_debug@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f7 <_remove_trailing_whitespace+0x177>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     12f1 <_remove_trailing_whitespace+0x171>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1090 <isspace@plt>
cmp    $0x0,%eax
je     12d2 <_remove_trailing_whitespace+0x152>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    12d7 <_remove_trailing_whitespace+0x157>
jmp    12f1 <_remove_trailing_whitespace+0x171>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    12a3 <_remove_trailing_whitespace+0x123>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_remove_trailing_whitespace>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
test   %rdi,%rdi
je     11cc <_remove_trailing_whitespace+0x5c>
mov    %esi,%eax
mov    %rdi,%r14
movslq %esi,%rbx
lea    (%rdi,%rbx,1),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rdi,%rcx
jb     1252 <_remove_trailing_whitespace+0xe2>
lea    -0x1(%r14),%r15
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edi
call   1080 <isspace@plt>
test   %eax,%eax
je     11c5 <_remove_trailing_whitespace+0x55>
movb   $0x0,-0x1(%r14,%rbx,1)
lea    (%r15,%rbx,1),%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rax
jae    11a0 <_remove_trailing_whitespace+0x30>
mov    %ebx,%eax
jmp    1252 <_remove_trailing_whitespace+0xe2>
mov    %rsp,%rbx
mov    $0x2000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe1b(%rip),%rdx
lea    0xe23(%rip),%rcx
lea    0xebe(%rip),%r8
mov    $0x2000,%esi
mov    %rbx,%rdi
mov    $0xa6,%r9d
xor    %eax,%eax
call   1040 <snprintf@plt>
cmp    $0x1fff,%eax
jg     1243 <_remove_trailing_whitespace+0xd3>
mov    %eax,%ebx
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1090 <_debug_msg_create@plt>
test   %eax,%eax
je     1243 <_remove_trailing_whitespace+0xd3>
movslq %eax,%r14
mov    $0x1fff,%eax
sub    %ebx,%eax
movslq %eax,%rdx
mov    %rsp,%rdi
mov    %r14,%rsi
call   1070 <strncat@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rsp,%rdi
xor    %eax,%eax
call   1060 <err_debug@plt>
mov    $0xffffffff,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [15 x i8] c"(%s, %s, %d): \00"
@.str.1 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chaos/whatsup/refs/heads/master/src/pingd/pingd_clusterlist_hostsfile.c\00"
@__FUNCTION__._remove_trailing_whitespace = [28 x i8] c"_remove_trailing_whitespace\00"
@.str.2 = [19 x i8] c"invalid parameters\00"
define i32 @_remove_trailing_whitespace(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [8192 x i8]
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %44, label %12
12: ; preds = %2
br label %13
13: ; preds = %12
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %15, i64 8192, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @__FUNCTION__._remove_trailing_whitespace, i64 0, i64 0), i32 166)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 8192
br i1 %18, label %19, label %40
19: ; preds = %13
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @_debug_msg_create to i32 (i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %9
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %39
24: ; preds = %19
%25 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %9
%27 = load i32, i32* %8
%28 = sub nsw i32 8192, %27
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = call i8* @strncat(i8* %25, i8* %26, i64 %30)
%32 = load i8*, i8** %9
%33 = call i64 @strlen(i8* %32)
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = add i64 %35, %33
%37 = trunc i64 %36 to i32
store i32 %37, i32* %8
%38 = load i8*, i8** %9
br label %39
39: ; preds = %24, %19
br label %40
40: ; preds = %39, %13
%41 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 0
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @err_debug to i32 (i8*, ...)*)(i8* %41)
br label %43
43: ; preds = %40
store i32 -1, i32* %3
br label %72
44: ; preds = %2
%45 = load i8*, i8** %4
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
store i8* %48, i8** %6
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i32 -1
store i8* %50, i8** %6
br label %51
51: ; preds = %67, %44
%52 = load i8*, i8** %6
%53 = load i8*, i8** %4
%54 = icmp uge i8* %52, %53
br i1 %54, label %55, label %70
55: ; preds = %51
%56 = load i8*, i8** %6
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = call i32 @isspace(i32 %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = load i8*, i8** %6
store i8 0, i8* %62
br label %64
63: ; preds = %55
br label %70
64: ; preds = %61
%65 = load i32, i32* %5
%66 = add nsw i32 %65, -1
store i32 %66, i32* %5
br label %67
67: ; preds = %64
%68 = load i8*, i8** %6
%69 = getelementptr inbounds i8, i8* %68, i32 -1
store i8* %69, i8** %6
br label %51
70: ; preds = %63, %51
%71 = load i32, i32* %5
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %43
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [15 x i8] c"(%s, %s, %d): \00"
@.str.1 = [162 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/chaos/whatsup/refs/heads/master/src/pingd/pingd_clusterlist_hostsfile.c\00"
@__FUNCTION__._remove_trailing_whitespace = [28 x i8] c"_remove_trailing_whitespace\00"
@.str.2 = [19 x i8] c"invalid parameters\00"
define i32 @_remove_trailing_whitespace(i8* %0, i32 %1) {
%3 = alloca [8192 x i8]
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %6, i64 8192, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @__FUNCTION__._remove_trailing_whitespace, i64 0, i64 0), i32 166)
%8 = icmp slt i32 %7, 8192
br i1 %8, label %9, label %18
9: ; preds = %5
%10 = tail call i32 (i8*, ...) bitcast (i32 (...)* @_debug_msg_create to i32 (i8*, ...)*)(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i32 %10, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = sub i32 8191, %7
%16 = sext i32 %15 to i64
%17 = call i8* @strncat(i8* %6, i8* %12, i64 %16)
br label %18
18: ; preds = %9, %14, %5
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @err_debug to i32 (i8*, ...)*)(i8* %6)
br label %36
20: ; preds = %2
%21 = sext i32 %1 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = getelementptr inbounds i8, i8* %22, i64 -1
%24 = icmp ult i8* %23, %0
br i1 %24, label %36, label %25
25: ; preds = %20, %32
%26 = phi i8* [ %34, %32 ], [ %23, %20 ]
%27 = phi i32 [ %33, %32 ], [ %1, %20 ]
%28 = load i8, i8* %26
%29 = sext i8 %28 to i32
%30 = tail call i32 @isspace(i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %25
store i8 0, i8* %26
%33 = add nsw i32 %27, -1
%34 = getelementptr inbounds i8, i8* %26, i64 -1
%35 = icmp ult i8* %34, %0
br i1 %35, label %36, label %25
36: ; preds = %25, %32, %20, %18
%37 = phi i32 [ -1, %18 ], [ %1, %20 ], [ %27, %25 ], [ %33, %32 ]
ret i32 %37
}