#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 dummy;
};

/* Variables and functions */
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void CheckFilename(char *result, char *filename) {
  struct stat buf_stat;
  strcpy(result, filename);
  strcat(result, ".zz");
  if (stat(filename, &buf_stat) != -1 || stat(result, &buf_stat) == -1)
    strcpy(result, filename);
}


x86 assembly (clang, -O0):
<CheckFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1189 <CheckFilename+0x59>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
jne    1196 <CheckFilename+0x66>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckFilename>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strcpy@plt>
lea    0xeba(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     1170 <CheckFilename+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <strcpy@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1040 <stat@plt>
cmp    $0xffffffff,%eax
je     115e <CheckFilename+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c".zz\00"
define void @CheckFilename(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = load i8*, i8** %3
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %4
%12 = call i32 @stat(i8* %11, %struct.stat* %5)
%13 = icmp ne i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @stat(i8* %15, %struct.stat* %5)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %14, %2
%19 = load i8*, i8** %3
%20 = load i8*, i8** %4
%21 = call i32 @strcpy(i8* %19, i8* %20)
br label %22
22: ; preds = %18, %14
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c".zz\00"
define void @CheckFilename(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @strcpy(i8* %0, i8* %1)
%6 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @stat(i8* %1, %struct.stat* %3)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = call i32 @stat(i8* %0, %struct.stat* %3)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %9, %2
%13 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %14
14: ; preds = %12, %9
ret void
}