#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
int S_IFDIR;
int /*<<< orphan*/ free(char *);
int stat(char *, struct stat *);
char *translate_suffix(char const *, char const *, char const *);
char *translate_file(const char *target_path, const char *suffix_source,
                     const char *suffix_target) {
  char *source_path =
      translate_suffix(target_path, suffix_target, suffix_source);
  if (!source_path) {
    return NULL;
  }
  struct stat data;
  int retstat = stat(source_path, &data);
  if (retstat != 0) {
    free(source_path);
    return NULL;
  }
  if (data.st_mode & S_IFDIR) {
    free(source_path);
    return NULL;
  }
  return source_path;
}


x86 assembly (clang, -O0):
<translate_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <translate_suffix@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1171 <translate_file+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <translate_file+0xa4>
mov    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11a1 <translate_file+0x71>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <translate_file+0xa4>
mov    -0x30(%rbp),%eax
mov    0x2e2d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11cc <translate_file+0x9c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d4 <translate_file+0xa4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_file>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rax
mov    %rdx,%rsi
mov    %rax,%rdx
call   1040 <translate_suffix@plt>
test   %rax,%rax
je     1173 <translate_file+0x43>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
test   %eax,%eax
jne    116b <translate_file+0x3b>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
test   %eax,0x8(%rsp)
je     1175 <translate_file+0x45>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i8* @translate_file(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.stat
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = load i8*, i8** %7
%13 = load i8*, i8** %6
%14 = call i8* @translate_suffix(i8* %11, i8* %12, i8* %13)
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i8* null, i8** %4
br label %37
18: ; preds = %3
%19 = load i8*, i8** %8
%20 = call i32 @stat(i8* %19, %struct.stat* %9)
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = call i32 @free(i8* %24)
store i8* null, i8** %4
br label %37
26: ; preds = %18
%27 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%28 = load i32, i32* %27
%29 = load i32, i32* @S_IFDIR
%30 = and i32 %28, %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i8*, i8** %8
%34 = call i32 @free(i8* %33)
store i8* null, i8** %4
br label %37
35: ; preds = %26
%36 = load i8*, i8** %8
store i8* %36, i8** %4
br label %37
37: ; preds = %35, %32, %23, %17
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFDIR = global i32 0
define i8* @translate_file(i8* %0, i8* %1, i8* %2) {
%4 = alloca %struct.stat
%5 = tail call i8* @translate_suffix(i8* %0, i8* %2, i8* %1)
%6 = icmp eq i8* %5, null
br i1 %6, label %21, label %7
7: ; preds = %3
%8 = bitcast %struct.stat* %4 to i8*
%9 = call i32 @stat(i8* %5, %struct.stat* %4)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = load i32, i32* @S_IFDIR
%15 = and i32 %14, %13
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %11, %7
%18 = tail call i32 @free(i8* %5)
br label %19
19: ; preds = %17, %11
%20 = phi i8* [ %5, %11 ], [ null, %17 ]
br label %21
21: ; preds = %3, %19
%22 = phi i8* [ %20, %19 ], [ null, %3 ]
ret i8* %22
}