#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int low_get_string(char **, int /*<<< orphan*/ *, char *, unsigned int,
                   unsigned int);
char *malloc(unsigned int);
int /*<<< orphan*/ memcpy(char *, char const *, unsigned int);
int get_filename(char **str, FILE *f, const char *prefix, unsigned pfxlen) {
  char *buf = malloc(pfxlen + 32);
  if (buf && prefix && pfxlen)
    memcpy(buf, prefix, pfxlen);
  return low_get_string(str, f, buf, pfxlen + 32, pfxlen);
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x20,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1186 <get_filename+0x56>
cmpq   $0x0,-0x18(%rbp)
je     1186 <get_filename+0x56>
cmpl   $0x0,-0x1c(%rbp)
je     1186 <get_filename+0x56>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
add    $0x20,%ecx
mov    -0x1c(%rbp),%r8d
call   1050 <low_get_string@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x20(%rbx),%r13d
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    %rax,%rbp
test   %ebx,%ebx
je     1170 <get_filename+0x40>
test   %r12,%r12
je     1170 <get_filename+0x40>
test   %rbp,%rbp
je     1170 <get_filename+0x40>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %ebx,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <low_get_string@plt>

LLVM IR (-O0):
define i32 @get_filename(i8** %0, i32* %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8** %0, i8*** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = add i32 %10, 32
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %26
15: ; preds = %4
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %26
18: ; preds = %15
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8*, i8** %9
%23 = load i8*, i8** %7
%24 = load i32, i32* %8
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
br label %26
26: ; preds = %21, %18, %15, %4
%27 = load i8**, i8*** %5
%28 = load i32*, i32** %6
%29 = load i8*, i8** %9
%30 = load i32, i32* %8
%31 = add i32 %30, 32
%32 = load i32, i32* %8
%33 = call i32 @low_get_string(i8** %27, i32* %28, i8* %29, i32 %31, i32 %32)
ret i32 %33
}

LLVM IR (-O2):
define i32 @get_filename(i8** %0, i32* %1, i8* %2, i32 %3) {
%5 = add i32 %3, 32
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp ne i8* %6, null
%8 = icmp ne i8* %2, null
%9 = and i1 %8, %7
%10 = icmp ne i32 %3, 0
%11 = and i1 %10, %9
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = tail call i32 @memcpy(i8* %6, i8* %2, i32 %3)
br label %14
14: ; preds = %12, %4
%15 = tail call i32 @low_get_string(i8** %0, i32* %1, i8* %6, i32 %5, i32 %3)
ret i32 %15
}