#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 /*<<< orphan*/ ProcessFiles(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void ProcessFilename(char *name) {
  char buffer[1000];
  FILE *in, *out;
  strcpy(buffer, name);
  if (strlen(buffer) > 4 && strcmp(buffer + strlen(buffer) - 4, ".sfd") == 0)
    strcpy(buffer + strlen(buffer) - 4, "-new.sfd");
  else
    strcat(buffer, "-new");
  in = fopen(name, "r");
  if (in == NULL) {
    fprintf(stderr, "Could not open %s for reading\n", name);
    exit(1);
  }
  out = fopen(buffer, "w");
  if (out == NULL) {
    fclose(in);
    fprintf(stderr, "Could not open %s for writing\n", buffer);
    exit(1);
  }
  ProcessFiles(in, out);
  fclose(in);
  fclose(out);
}


x86 assembly (clang, -O0):
<ProcessFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x3f0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x3f0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x4,%eax
jle    123f <ProcessFilename+0xaf>
lea    -0x3f0(%rbp),%rax
mov    %rax,-0x408(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x408(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe0f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    123f <ProcessFilename+0xaf>
lea    -0x3f0(%rbp),%rax
mov    %rax,-0x410(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x410(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xdcb(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1252 <ProcessFilename+0xc2>
lea    -0x3f0(%rbp),%rdi
lea    0xdbc(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xdb1(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x3f8(%rbp)
cmpq   $0x0,-0x3f8(%rbp)
jne    129a <ProcessFilename+0x10a>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x3f0(%rbp),%rdi
lea    0xd64(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x400(%rbp)
cmpq   $0x0,-0x400(%rbp)
jne    12f4 <ProcessFilename+0x164>
mov    -0x3f8(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    -0x3f0(%rbp),%rdx
lea    0xd4a(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x3f8(%rbp),%rdi
mov    -0x400(%rbp),%rsi
call   1030 <ProcessFiles@plt>
mov    -0x3f8(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x400(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ProcessFilename>:
push   %r15
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x5,%eax
jl     11dd <ProcessFilename+0x4d>
mov    %rsp,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe31(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1242 <ProcessFilename+0xb2>
lea    0xe25(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <strcat@plt>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1262 <ProcessFilename+0xd2>
mov    %rax,%r15
lea    0xe02(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1277 <ProcessFilename+0xe7>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <ProcessFiles@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xda5(%rip),%rsi
call   1040 <strcpy@plt>
jmp    11ec <ProcessFilename+0x5c>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
mov    %r14,%rdx
jmp    1292 <ProcessFilename+0x102>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
mov    %rsp,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c".sfd\00"
@.str.1 = [9 x i8] c"-new.sfd\00"
@.str.2 = [5 x i8] c"-new\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [31 x i8] c"Could not open %s for reading\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [31 x i8] c"Could not open %s for writing\0A\00"
define void @ProcessFilename(i8* %0) {
%2 = alloca i8*
%3 = alloca [1000 x i8]
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %2
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @strcpy(i8* %6, i8* %7)
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 4
br i1 %11, label %12, label %29
12: ; preds = %1
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -4
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %12
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -4
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %32
29: ; preds = %12, %1
%30 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %29, %21
%33 = load i8*, i8** %2
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %34, i32** %4
%35 = load i32*, i32** %4
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %42
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %2
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %32
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%44 = call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %44, i32** %5
%45 = load i32*, i32** %5
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %54
47: ; preds = %42
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
%50 = load i32, i32* @stderr
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%52 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %42
%55 = load i32*, i32** %4
%56 = load i32*, i32** %5
%57 = call i32 @ProcessFiles(i32* %55, i32* %56)
%58 = load i32*, i32** %4
%59 = call i32 @fclose(i32* %58)
%60 = load i32*, i32** %5
%61 = call i32 @fclose(i32* %60)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c".sfd\00"
@.str.1 = [9 x i8] c"-new.sfd\00"
@.str.2 = [5 x i8] c"-new\00"
@.str.3 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.4 = [31 x i8] c"Could not open %s for reading\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [31 x i8] c"Could not open %s for writing\0A\00"
define void @ProcessFilename(i8* %0) {
%2 = alloca [1000 x i8]
%3 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%4 = call i32 @strcpy(i8* %3, i8* %0)
%5 = call i32 @strlen(i8* %3)
%6 = icmp sgt i32 %5, 4
br i1 %6, label %7, label %20
7: ; preds = %1
%8 = call i32 @strlen(i8* %3)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -4
%12 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = call i32 @strlen(i8* %3)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %16
%18 = getelementptr inbounds i8, i8* %17, i64 -4
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %7, %1
%21 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %14
%23 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = call i32 @fclose(i32* %23)
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = call i32 @ProcessFiles(i32* %23, i32* %30)
%39 = call i32 @fclose(i32* %23)
%40 = call i32 @fclose(i32* %30)
ret void
}