#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*/ memmove(char *, char *, int);
int /*<<< orphan*/ pmesg(int, char *, int, char *);
int strlen(char *);
int trim(char *string) {
  if (!string) {
    pmesg(1,
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-io-server/refs/"
          "heads/master/src/common/oph_server_utility.c",
          355, "Null input parameter\n");
    return 1;
  }
  char *p = string;
  int l = strlen(p);
  while (isspace(p[l - 1]))
    p[--l] = 0;
  while (*p && isspace(*p))
    ++p, --l;
  memmove(string, p, l + 1);
  return 0;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <trim+0x40>
mov    $0x1,%edi
lea    0xe9d(%rip),%rsi
mov    $0x163,%edx
lea    0xf3e(%rip),%rcx
call   1050 <pmesg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1241 <trim+0x101>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     11cd <trim+0x8d>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x1c(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1194 <trim+0x54>
jmp    11d2 <trim+0x92>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     11fd <trim+0xbd>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    120d <trim+0xcd>
jmp    1227 <trim+0xe7>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d2 <trim+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1060 <memmove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     11e0 <trim+0xa0>
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ebp
movslq %eax,%rbx
movsbl -0x1(%rbx,%r14,1),%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     1198 <trim+0x58>
add    %r14,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rbx)
movsbl -0x1(%rbx),%edi
add    $0xffffffffffffffff,%rbx
call   1040 <isspace@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    1180 <trim+0x40>
mov    (%r14),%al
mov    %r14,%rbx
test   %al,%al
je     11cc <trim+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
je     11cc <trim+0x8c>
add    $0xffffffff,%ebp
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11b0 <trim+0x70>
add    $0x1,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <memmove@plt>
xor    %ebx,%ebx
jmp    1202 <trim+0xc2>
lea    0xe19(%rip),%rsi
lea    0xebf(%rip),%rcx
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x163,%edx
call   1050 <pmesg@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-io-server/refs/heads/master/src/common/oph_server_utility.c\00"
@.str.1 = [22 x i8] c"Null input parameter\0A\00"
define i32 @trim(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 @pmesg(i32 1, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 355, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %2
br label %53
10: ; preds = %1
%11 = load i8*, i8** %3
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %5
br label %14
14: ; preds = %23, %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @isspace(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
br label %14
29: ; preds = %14
br label %30
30: ; preds = %42, %29
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = load i8, i8* %36
%38 = call i64 @isspace(i8 signext %37)
%39 = icmp ne i64 %38, 0
br label %40
40: ; preds = %35, %30
%41 = phi i1 [ false, %30 ], [ %39, %35 ]
br i1 %41, label %42, label %47
42: ; preds = %40
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %4
%45 = load i32, i32* %5
%46 = add nsw i32 %45, -1
store i32 %46, i32* %5
br label %30
47: ; preds = %40
%48 = load i8*, i8** %3
%49 = load i8*, i8** %4
%50 = load i32, i32* %5
%51 = add nsw i32 %50, 1
%52 = call i32 @memmove(i8* %48, i8* %49, i32 %51)
store i32 0, i32* %2
br label %53
53: ; preds = %47, %8
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OphidiaBigData/ophidia-io-server/refs/heads/master/src/common/oph_server_utility.c\00"
@.str.1 = [22 x i8] c"Null input parameter\0A\00"
define i32 @trim(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @pmesg(i32 1, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0), i32 355, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %43
5: ; preds = %1
%6 = tail call i32 @strlen(i8* %0)
%7 = add nsw i32 %6, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @isspace(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %19
13: ; preds = %19
%14 = trunc i64 %20 to i32
br label %15
15: ; preds = %13, %5
%16 = phi i32 [ %6, %5 ], [ %14, %13 ]
%17 = load i8, i8* %0
%18 = icmp eq i8 %17, 0
br i1 %18, label %38, label %27
19: ; preds = %5, %19
%20 = phi i64 [ %22, %19 ], [ %8, %5 ]
%21 = phi i8* [ %23, %19 ], [ %9, %5 ]
store i8 0, i8* %21
%22 = add i64 %20, -1
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = load i8, i8* %23
%25 = tail call i64 @isspace(i8 signext %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %13, label %19
27: ; preds = %15, %33
%28 = phi i8 [ %36, %33 ], [ %17, %15 ]
%29 = phi i32 [ %35, %33 ], [ %16, %15 ]
%30 = phi i8* [ %34, %33 ], [ %0, %15 ]
%31 = tail call i64 @isspace(i8 signext %28)
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %27
%34 = getelementptr inbounds i8, i8* %30, i64 1
%35 = add nsw i32 %29, -1
%36 = load i8, i8* %34
%37 = icmp eq i8 %36, 0
br i1 %37, label %38, label %27
38: ; preds = %27, %33, %15
%39 = phi i8* [ %0, %15 ], [ %34, %33 ], [ %30, %27 ]
%40 = phi i32 [ %16, %15 ], [ %35, %33 ], [ %29, %27 ]
%41 = add nsw i32 %40, 1
%42 = tail call i32 @memmove(i8* %0, i8* %39, i32 %41)
br label %43
43: ; preds = %38, %3
%44 = phi i32 [ 0, %38 ], [ 1, %3 ]
ret i32 %44
}