#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 */

/* Variables and functions */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, ...);
scalar_t__ strlen(char *);
char *validate_outfile_status(int status, char *edit_filename) {
  char *errstr = NULL;
  if (status) {
    errstr = (char *)malloc(strlen(edit_filename) + 50);
    if (!errstr) {
      return NULL;
    }
    if (status == 1) {
      sprintf(errstr, "Output file '%s' already exists", edit_filename);
    } else if (status == 2) {
      sprintf(errstr, "Output file '%s' is not writable for append",
              edit_filename);
    } else if (status == 3) {
      sprintf(errstr, "No file was specified");
    } else if (status == 4) {
      sprintf(errstr, "Directory in path does not exist '%s'", edit_filename);
    } else if (status == 5) {
      sprintf(errstr, "Directory in path is not writable '%s'", edit_filename);
    } else {
      sprintf(errstr, "Error using output file '%s'", edit_filename);
    }
  }
  return errstr;
}


x86 assembly (clang, -O0):
<validate_outfile_status>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1266 <validate_outfile_status+0x136>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x32,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1182 <validate_outfile_status+0x52>
movq   $0x0,-0x8(%rbp)
jmp    126e <validate_outfile_status+0x13e>
cmpl   $0x1,-0xc(%rbp)
jne    11a7 <validate_outfile_status+0x77>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1261 <validate_outfile_status+0x131>
cmpl   $0x2,-0xc(%rbp)
jne    11cc <validate_outfile_status+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    125c <validate_outfile_status+0x12c>
cmpl   $0x3,-0xc(%rbp)
jne    11ed <validate_outfile_status+0xbd>
mov    -0x20(%rbp),%rdi
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1257 <validate_outfile_status+0x127>
cmpl   $0x4,-0xc(%rbp)
jne    1212 <validate_outfile_status+0xe2>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1252 <validate_outfile_status+0x122>
cmpl   $0x5,-0xc(%rbp)
jne    1237 <validate_outfile_status+0x107>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    124d <validate_outfile_status+0x11d>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1252 <validate_outfile_status+0x122>
jmp    1257 <validate_outfile_status+0x127>
jmp    125c <validate_outfile_status+0x12c>
jmp    1261 <validate_outfile_status+0x131>
jmp    1266 <validate_outfile_status+0x136>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_outfile_status>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
je     1178 <validate_outfile_status+0x48>
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x32(%rax),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1178 <validate_outfile_status+0x48>
mov    %rax,%r15
add    $0xffffffff,%ebx
cmp    $0x4,%ebx
ja     117d <validate_outfile_status+0x4d>
lea    0xe9a(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xe9e(%rip),%rsi
jmp    11ba <validate_outfile_status+0x8a>
xor    %r15d,%r15d
jmp    11c7 <validate_outfile_status+0x97>
lea    0xf3f(%rip),%rsi
jmp    11ba <validate_outfile_status+0x8a>
lea    0xea7(%rip),%rsi
jmp    11ba <validate_outfile_status+0x8a>
movups 0xeca(%rip),%xmm0
movups %xmm0,(%r15)
movabs $0x64656966696365,%rax
mov    %rax,0xe(%r15)
jmp    11c7 <validate_outfile_status+0x97>
lea    0xec5(%rip),%rsi
jmp    11ba <validate_outfile_status+0x8a>
lea    0xee2(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Output file '%s' already exists\00"
@.str.1 = [44 x i8] c"Output file '%s' is not writable for append\00"
@.str.2 = [22 x i8] c"No file was specified\00"
@.str.3 = [38 x i8] c"Directory in path does not exist '%s'\00"
@.str.4 = [39 x i8] c"Directory in path is not writable '%s'\00"
@.str.5 = [29 x i8] c"Error using output file '%s'\00"
define i8* @validate_outfile_status(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* null, i8** %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %61
9: ; preds = %2
%10 = load i8*, i8** %5
%11 = call i64 @strlen(i8* %10)
%12 = add nsw i64 %11, 50
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %9
store i8* null, i8** %3
br label %63
18: ; preds = %9
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = load i8*, i8** %5
%24 = call i32 (i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23)
br label %60
25: ; preds = %18
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = load i8*, i8** %5
%31 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %30)
br label %59
32: ; preds = %25
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 3
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %6
%37 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %58
38: ; preds = %32
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 4
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = load i8*, i8** %5
%44 = call i32 (i8*, i8*, ...) @sprintf(i8* %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %57
45: ; preds = %38
%46 = load i32, i32* %4
%47 = icmp eq i32 %46, 5
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i8*, i8** %6
%50 = load i8*, i8** %5
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %49, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %50)
br label %56
52: ; preds = %45
%53 = load i8*, i8** %6
%54 = load i8*, i8** %5
%55 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %52, %48
br label %57
57: ; preds = %56, %41
br label %58
58: ; preds = %57, %35
br label %59
59: ; preds = %58, %28
br label %60
60: ; preds = %59, %21
br label %61
61: ; preds = %60, %2
%62 = load i8*, i8** %6
store i8* %62, i8** %3
br label %63
63: ; preds = %61, %17
%64 = load i8*, i8** %3
ret i8* %64
}

LLVM IR (-O2):
@.str = [32 x i8] c"Output file '%s' already exists\00"
@.str.1 = [44 x i8] c"Output file '%s' is not writable for append\00"
@.str.2 = [22 x i8] c"No file was specified\00"
@.str.3 = [38 x i8] c"Directory in path does not exist '%s'\00"
@.str.4 = [39 x i8] c"Directory in path is not writable '%s'\00"
@.str.5 = [29 x i8] c"Error using output file '%s'\00"
define i8* @validate_outfile_status(i32 %0, i8* %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %22, label %4
4: ; preds = %2
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = add nsw i64 %5, 50
%7 = tail call i64 @malloc(i64 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %22, label %10
10: ; preds = %4
switch i32 %0, label %20 [
i32 1, label %11
i32 2, label %13
i32 3, label %15
i32 4, label %16
i32 5, label %18
]
11: ; preds = %10
%12 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %22
13: ; preds = %10
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %22
15: ; preds = %10
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(22) %8, i8* align 1 dereferenceable(22) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i64 22, i1 false)
br label %22
16: ; preds = %10
%17 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %22
18: ; preds = %10
%19 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %1)
br label %22
20: ; preds = %10
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* %1)
br label %22
22: ; preds = %2, %13, %16, %20, %18, %15, %11, %4
%23 = phi i8* [ null, %4 ], [ %8, %11 ], [ %8, %13 ], [ %8, %15 ], [ %8, %16 ], [ %8, %18 ], [ %8, %20 ], [ null, %2 ]
ret i8* %23
}