#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 /*<<< orphan*/ crash();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
void checkfiles(char *infile, char *outfile) {
  struct stat buf;
  if (infile)
    if (stat(infile, &buf) < 0) {
      perror(infile);
      crash();
    };
  if (outfile) {
    if (stat(outfile, &buf) < 0)
      return;
    else {
      (void)fprintf(stderr, "file '%s' already exists and may be overwritten\n",
                    outfile);
      crash();
    }
  }
}


x86 assembly (clang, -O0):
<checkfiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1187 <checkfiles+0x47>
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    1182 <checkfiles+0x42>
mov    -0x8(%rbp),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <crash@plt>
jmp    1187 <checkfiles+0x47>
cmpq   $0x0,-0x10(%rbp)
je     11d3 <checkfiles+0x93>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
jge    11ae <checkfiles+0x6e>
jmp    11d3 <checkfiles+0x93>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <crash@plt>
jmp    11d3 <checkfiles+0x93>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkfiles>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     115c <checkfiles+0x1c>
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1050 <stat@plt>
test   %rax,%rax
js     1198 <checkfiles+0x58>
test   %r14,%r14
je     1190 <checkfiles+0x50>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <stat@plt>
test   %rax,%rax
js     1190 <checkfiles+0x50>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <crash@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %rbx,%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <crash@plt>
test   %r14,%r14
jne    1161 <checkfiles+0x21>
jmp    1190 <checkfiles+0x50>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"file '%s' already exists and may be overwritten\0A\00"
define void @checkfiles(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 = icmp ne i8* %6, null
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i64 @stat(i8* %9, %struct.stat* %5)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = call i32 @perror(i8* %13)
%15 = call i32 (...) @crash()
br label %16
16: ; preds = %12, %8
br label %17
17: ; preds = %16, %2
%18 = load i8*, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %31
20: ; preds = %17
%21 = load i8*, i8** %4
%22 = call i64 @stat(i8* %21, %struct.stat* %5)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %31
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %4
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 (...) @crash()
br label %30
30: ; preds = %25
br label %31
31: ; preds = %24, %30, %17
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [49 x i8] c"file '%s' already exists and may be overwritten\0A\00"
define void @checkfiles(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = call i64 @stat(i8* %0, %struct.stat* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = call i32 @perror(i8* %0)
%11 = call i32 (...) @crash()
br label %12
12: ; preds = %6, %9, %2
%13 = icmp eq i8* %1, null
br i1 %13, label %21, label %14
14: ; preds = %12
%15 = call i64 @stat(i8* %1, %struct.stat* %3)
%16 = icmp slt i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %1)
%20 = call i32 (...) @crash()
br label %21
21: ; preds = %12, %17, %14
ret void
}