#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 */
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xmalloc(scalar_t__);
char *trim(const char *fn) {
  char *name;
  while (fn[0] == '.' && fn[1] == '/')
    fn += 2;
  name = xmalloc(strlen(fn) + 1);
  if (name == 0)
    return 0;
  strcpy(name, fn);
  return name;
}


x86 assembly (clang, -O0):
<trim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x2e,%ecx
mov    %al,-0x19(%rbp)
jne    1162 <trim+0x32>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1172 <trim+0x42>
jmp    1183 <trim+0x53>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    113c <trim+0xc>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <trim+0x84>
movq   $0x0,-0x8(%rbp)
jmp    11c9 <trim+0x99>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trim>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x2e,(%rdi)
jne    1155 <trim+0x25>
nopl   0x0(%rax)
cmpb   $0x2f,0x1(%rdi)
jne    1155 <trim+0x25>
lea    0x2(%rdi),%rbx
cmpb   $0x2e,0x2(%rdi)
mov    %rbx,%rdi
je     1140 <trim+0x10>
jmp    1158 <trim+0x28>
mov    %rdi,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <xmalloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     117c <trim+0x4c>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @trim(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
br label %5
5: ; preds = %19, %1
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 46
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br label %17
17: ; preds = %11, %5
%18 = phi i1 [ false, %5 ], [ %16, %11 ]
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 2
store i8* %21, i8** %3
br label %5
22: ; preds = %17
%23 = load i8*, i8** %3
%24 = call i64 @strlen(i8* %23)
%25 = add nsw i64 %24, 1
%26 = call i8* @xmalloc(i64 %25)
store i8* %26, i8** %4
%27 = load i8*, i8** %4
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %22
store i8* null, i8** %2
br label %35
30: ; preds = %22
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %31, i8* %32)
%34 = load i8*, i8** %4
store i8* %34, i8** %2
br label %35
35: ; preds = %30, %29
%36 = load i8*, i8** %2
ret i8* %36
}

LLVM IR (-O2):
define i8* @trim(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 46
br i1 %3, label %4, label %13
4: ; preds = %1, %9
%5 = phi i8* [ %10, %9 ], [ %0, %1 ]
%6 = getelementptr inbounds i8, i8* %5, i64 1
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 47
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = getelementptr inbounds i8, i8* %5, i64 2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %4, label %13
13: ; preds = %4, %9, %1
%14 = phi i8* [ %0, %1 ], [ %10, %9 ], [ %5, %4 ]
%15 = tail call i64 @strlen(i8* %14)
%16 = add nsw i64 %15, 1
%17 = tail call i8* @xmalloc(i64 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = tail call i32 @strcpy(i8* %17, i8* %14)
br label %21
21: ; preds = %13, %19
ret i8* %17
}