#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 */
char *ckmalloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *getfilename(char *str) {
  if (*str == '\"') {
    char *buf;
    str++;
    buf = ckmalloc(strlen(str) + 1);
    strcpy(buf, str);
    for (str = buf; *str && *str != '\"'; ++str)
      ;
    *str = 0;
    return buf;
  }
  return str;
}


x86 assembly (clang, -O0):
<getfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11e5 <getfilename+0xb5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <ckmalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     11ab <getfilename+0x7b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11bb <getfilename+0x8b>
jmp    11d1 <getfilename+0xa1>
jmp    11c0 <getfilename+0x90>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1186 <getfilename+0x56>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <getfilename+0xbd>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfilename>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x22,(%rdi)
jne    1185 <getfilename+0x55>
mov    %rbx,%r14
add    $0x1,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <ckmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rax),%ecx
test   %cl,%cl
je     1182 <getfilename+0x52>
cmp    $0x22,%cl
je     1182 <getfilename+0x52>
add    $0x1,%rax
jmp    1170 <getfilename+0x40>
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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