#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
scalar_t__ strlen(char *);
char *validate_edit_times_errorstr(char *filename, char *timespec, int status) {
  char *errstr = malloc(128 + strlen(filename));
  *errstr = '\0';
  switch (status) {
  case 1:
    sprintf(errstr, "file name '%s' invalid", filename);
    break;
  case 2:
  case 3:
    sprintf(errstr, "file '%s', bad start time '%s'", filename, timespec);
    break;
  case 4:
    sprintf(errstr, "file '%s', start time is larger than end time '%s'",
            filename, timespec);
    break;
  case 5:
    sprintf(errstr, "file '%s', bad end time '%s'", filename, timespec);
    break;
  default:
    break;
  }
  return errstr;
}


x86 assembly (clang, -O0):
<validate_edit_times_errorstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
sub    $0xffffffffffffff80,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     1204 <validate_edit_times_errorstr+0xd4>
mov    -0x28(%rbp),%rax
lea    0xe7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1209 <validate_edit_times_errorstr+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1209 <validate_edit_times_errorstr+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1209 <validate_edit_times_errorstr+0xd9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1209 <validate_edit_times_errorstr+0xd9>
jmp    1209 <validate_edit_times_errorstr+0xd9>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_edit_times_errorstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r14
call   1030 <strlen@plt>
lea    0x80(%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
movb   $0x0,(%rax)
add    $0xffffffff,%ebx
cmp    $0x4,%ebx
ja     11ae <validate_edit_times_errorstr+0x7e>
lea    0xe9a(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    0xeb5(%rip),%rsi
jmp    119e <validate_edit_times_errorstr+0x6e>
lea    0xe95(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
jmp    11ae <validate_edit_times_errorstr+0x7e>
lea    0xeb5(%rip),%rsi
jmp    119e <validate_edit_times_errorstr+0x6e>
lea    0xedf(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [23 x i8] c"file name '%s' invalid\00"
@.str.1 = [31 x i8] c"file '%s', bad start time '%s'\00"
@.str.2 = [51 x i8] c"file '%s', start time is larger than end time '%s'\00"
@.str.3 = [29 x i8] c"file '%s', bad end time '%s'\00"
define i8* @validate_edit_times_errorstr(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 128, %9
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %7
%12 = load i8*, i8** %7
store i8 0, i8* %12
%13 = load i32, i32* %6
switch i32 %13, label %33 [
i32 1, label %14
i32 2, label %18
i32 3, label %18
i32 4, label %23
i32 5, label %28
]
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load i8*, i8** %4
%17 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %34
18: ; preds = %3, %3
%19 = load i8*, i8** %7
%20 = load i8*, i8** %4
%21 = load i8*, i8** %5
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
br label %34
23: ; preds = %3
%24 = load i8*, i8** %7
%25 = load i8*, i8** %4
%26 = load i8*, i8** %5
%27 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %25, i8* %26)
br label %34
28: ; preds = %3
%29 = load i8*, i8** %7
%30 = load i8*, i8** %4
%31 = load i8*, i8** %5
%32 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %30, i8* %31)
br label %34
33: ; preds = %3
br label %34
34: ; preds = %33, %28, %23, %18, %14
%35 = load i8*, i8** %7
ret i8* %35
}

LLVM IR (-O2):
@.str = [23 x i8] c"file name '%s' invalid\00"
@.str.1 = [31 x i8] c"file '%s', bad start time '%s'\00"
@.str.2 = [51 x i8] c"file '%s', start time is larger than end time '%s'\00"
@.str.3 = [29 x i8] c"file '%s', bad end time '%s'\00"
define noalias i8* @validate_edit_times_errorstr(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 128
%6 = tail call i8* @malloc(i64 %5)
store i8 0, i8* %6
switch i32 %2, label %15 [
i32 1, label %7
i32 2, label %9
i32 3, label %9
i32 4, label %11
i32 5, label %13
]
7: ; preds = %3
%8 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
9: ; preds = %3, %3
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %15
11: ; preds = %3
%12 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
br label %15
13: ; preds = %3
%14 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
br label %15
15: ; preds = %3, %13, %11, %9, %7
ret i8* %6
}