#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 */
int /*<<< orphan*/ Eprintf(char *);
int /*<<< orphan*/ PError(char *);
int /*<<< orphan*/ exit(int);
scalar_t__ isascii(char);
char *realloc(char *, scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void autoset_outfile_name(const char *mode, const char *in_name,
                          char **outfile) {
  int len, i;
  if (**outfile == '-')
    return;
  if (isascii(**outfile) && strlen(*outfile) > 0) {
    return;
  }
  if (*in_name == '-')
    len = 0;
  else
    len = (int)strlen(in_name);
  if (len == 0) {
    *outfile = "hp2xx.out";
    return;
  }
  for (i = len - 1; i; i--)
    if (in_name[i] == '.')
      break;
  i++;
  if ((*outfile = realloc(*outfile, len + 2 + strlen(mode))) == NULL) {
    Eprintf("Error: No mem for output file name!\n");
    PError("autoset_outfile_name");
    exit((-1));
  }
  strcpy(*outfile, in_name);
  if (strcmp(mode, "pre") == 0)
    return;
  if (i == 1 || len - i > 3) {
    strcat(*outfile, ".");
    strcat(*outfile, mode);
  } else
    strcpy(*outfile + i, mode);
}


x86 assembly (clang, -O0):
<autoset_outfile_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11bc <autoset_outfile_name+0x2c>
jmp    1368 <autoset_outfile_name+0x1d8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   10b0 <isascii@plt>
cmp    $0x0,%rax
je     11f0 <autoset_outfile_name+0x60>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11f0 <autoset_outfile_name+0x60>
jmp    1368 <autoset_outfile_name+0x1d8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    120c <autoset_outfile_name+0x7c>
movl   $0x0,-0x1c(%rbp)
jmp    1218 <autoset_outfile_name+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1235 <autoset_outfile_name+0xa5>
mov    -0x18(%rbp),%rax
lea    0xdd3(%rip),%rcx
mov    %rcx,(%rax)
jmp    1368 <autoset_outfile_name+0x1d8>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1275 <autoset_outfile_name+0xe5>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1262 <autoset_outfile_name+0xd2>
jmp    1275 <autoset_outfile_name+0xe5>
jmp    1267 <autoset_outfile_name+0xd7>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    123e <autoset_outfile_name+0xae>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdi
add    %rax,%rsi
call   1070 <realloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    12e1 <autoset_outfile_name+0x151>
lea    0xd44(%rip),%rdi
call   1090 <Eprintf@plt>
lea    0xd5d(%rip),%rdi
call   1060 <PError@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
lea    0xd48(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1310 <autoset_outfile_name+0x180>
jmp    1368 <autoset_outfile_name+0x1d8>
cmpl   $0x1,-0x20(%rbp)
je     1329 <autoset_outfile_name+0x199>
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cmp    $0x3,%eax
jle    1351 <autoset_outfile_name+0x1c1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd11(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <strcat@plt>
jmp    1368 <autoset_outfile_name+0x1d8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
movslq -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<autoset_outfile_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdx),%rax
mov    (%rax),%al
cmp    $0x2d,%al
je     120f <autoset_outfile_name+0x7f>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
movsbl %al,%edi
call   10b0 <isascii@plt>
test   %rax,%rax
je     11c7 <autoset_outfile_name+0x37>
mov    (%rbx),%rdi
call   1040 <strlen@plt>
test   %rax,%rax
jg     120f <autoset_outfile_name+0x7f>
cmpb   $0x2d,(%r15)
je     1205 <autoset_outfile_name+0x75>
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
test   %r12d,%r12d
je     1205 <autoset_outfile_name+0x75>
movslq %r12d,%rax
lea    0x1(%r12),%r13d
add    %r15,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax)
cmp    $0x2,%r13d
je     121e <autoset_outfile_name+0x8e>
add    $0xffffffff,%r13d
cmpb   $0x2e,(%rax)
lea    -0x1(%rax),%rax
jne    11f0 <autoset_outfile_name+0x60>
jmp    1224 <autoset_outfile_name+0x94>
lea    0xdf4(%rip),%rax
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r13d
mov    (%rbx),%rax
mov    %rax,(%rsp)
mov    %r12d,%eax
add    $0x2,%eax
movslq %eax,%rbp
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %rax,%rbp
mov    (%rsp),%rdi
mov    %rbp,%rsi
call   1070 <realloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     12c5 <autoset_outfile_name+0x135>
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xddf(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120f <autoset_outfile_name+0x7f>
mov    (%rbx),%rdi
cmp    $0x1,%r13d
je     12a0 <autoset_outfile_name+0x110>
sub    %r13d,%r12d
cmp    $0x4,%r12d
jge    12a0 <autoset_outfile_name+0x110>
movslq %r13d,%rax
add    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>
lea    0xda1(%rip),%rsi
call   1080 <strcat@plt>
mov    (%rbx),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <strcat@plt>
lea    0xd3e(%rip),%rdi
call   1090 <Eprintf@plt>
lea    0xd57(%rip),%rdi
call   1060 <PError@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"hp2xx.out\00"
@.str.1 = [37 x i8] c"Error: No mem for output file name!\0A\00"
@.str.2 = [21 x i8] c"autoset_outfile_name\00"
@.str.3 = [4 x i8] c"pre\00"
@.str.4 = [2 x i8] c".\00"
define void @autoset_outfile_name(i8* %0, i8* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8** %2, i8*** %6
%9 = load i8**, i8*** %6
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 45
br i1 %13, label %14, label %15
14: ; preds = %3
br label %112
15: ; preds = %3
%16 = load i8**, i8*** %6
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = call i64 @isascii(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = call i64 @strlen(i8* %23)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
br label %112
27: ; preds = %21, %15
%28 = load i8*, i8** %5
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 45
br i1 %31, label %32, label %33
32: ; preds = %27
store i32 0, i32* %7
br label %37
33: ; preds = %27
%34 = load i8*, i8** %5
%35 = call i64 @strlen(i8* %34)
%36 = trunc i64 %35 to i32
store i32 %36, i32* %7
br label %37
37: ; preds = %33, %32
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = load i8**, i8*** %6
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %41
br label %112
42: ; preds = %37
%43 = load i32, i32* %7
%44 = sub nsw i32 %43, 1
store i32 %44, i32* %8
br label %45
45: ; preds = %58, %42
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = load i8*, i8** %5
%50 = load i32, i32* %8
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 46
br i1 %55, label %56, label %57
56: ; preds = %48
br label %61
57: ; preds = %48
br label %58
58: ; preds = %57
%59 = load i32, i32* %8
%60 = add nsw i32 %59, -1
store i32 %60, i32* %8
br label %45
61: ; preds = %56, %45
%62 = load i32, i32* %8
%63 = add nsw i32 %62, 1
store i32 %63, i32* %8
%64 = load i8**, i8*** %6
%65 = load i8*, i8** %64
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 2
%68 = sext i32 %67 to i64
%69 = load i8*, i8** %4
%70 = call i64 @strlen(i8* %69)
%71 = add nsw i64 %68, %70
%72 = call i8* @realloc(i8* %65, i64 %71)
%73 = load i8**, i8*** %6
store i8* %72, i8** %73
%74 = icmp eq i8* %72, null
br i1 %74, label %75, label %79
75: ; preds = %61
%76 = call i32 @Eprintf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%77 = call i32 @PError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%78 = call i32 @exit(i32 -1)
unreachable
79: ; preds = %61
%80 = load i8**, i8*** %6
%81 = load i8*, i8** %80
%82 = load i8*, i8** %5
%83 = call i32 @strcpy(i8* %81, i8* %82)
%84 = load i8*, i8** %4
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %79
br label %112
88: ; preds = %79
%89 = load i32, i32* %8
%90 = icmp eq i32 %89, 1
br i1 %90, label %96, label %91
91: ; preds = %88
%92 = load i32, i32* %7
%93 = load i32, i32* %8
%94 = sub nsw i32 %92, %93
%95 = icmp sgt i32 %94, 3
br i1 %95, label %96, label %104
96: ; preds = %91, %88
%97 = load i8**, i8*** %6
%98 = load i8*, i8** %97
%99 = call i32 @strcat(i8* %98, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%100 = load i8**, i8*** %6
%101 = load i8*, i8** %100
%102 = load i8*, i8** %4
%103 = call i32 @strcat(i8* %101, i8* %102)
br label %112
104: ; preds = %91
%105 = load i8**, i8*** %6
%106 = load i8*, i8** %105
%107 = load i32, i32* %8
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %106, i64 %108
%110 = load i8*, i8** %4
%111 = call i32 @strcpy(i8* %109, i8* %110)
br label %112
112: ; preds = %14, %26, %40, %87, %104, %96
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"hp2xx.out\00"
@.str.1 = [37 x i8] c"Error: No mem for output file name!\0A\00"
@.str.2 = [21 x i8] c"autoset_outfile_name\00"
@.str.3 = [4 x i8] c"pre\00"
@.str.4 = [2 x i8] c".\00"
define void @autoset_outfile_name(i8* %0, i8* %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 45
br i1 %6, label %68, label %7
7: ; preds = %3
%8 = tail call i64 @isascii(i8 signext %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %68, label %14
14: ; preds = %10, %7
%15 = load i8, i8* %1
%16 = icmp eq i8 %15, 45
br i1 %16, label %24, label %17
17: ; preds = %14
%18 = tail call i64 @strlen(i8* %1)
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = shl i64 %18, 32
%23 = ashr exact i64 %22, 32
br label %25
24: ; preds = %14, %17
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %2
br label %68
25: ; preds = %21, %30
%26 = phi i64 [ %23, %21 ], [ %27, %30 ]
%27 = add nsw i64 %26, -1
%28 = trunc i64 %27 to i32
%29 = icmp eq i32 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %25
%31 = getelementptr inbounds i8, i8* %1, i64 %27
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 46
br i1 %33, label %34, label %25
34: ; preds = %30
%35 = trunc i64 %26 to i32
br label %36
36: ; preds = %25, %34
%37 = phi i32 [ %35, %34 ], [ 1, %25 ]
%38 = load i8*, i8** %2
%39 = shl i64 %18, 32
%40 = add i64 %39, 8589934592
%41 = ashr exact i64 %40, 32
%42 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%43 = add nsw i64 %42, %41
%44 = tail call i8* @realloc(i8* %38, i64 %43)
store i8* %44, i8** %2
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %50
46: ; preds = %36
%47 = tail call i32 @Eprintf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%48 = tail call i32 @PError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%49 = tail call i32 @exit(i32 -1)
unreachable
50: ; preds = %36
%51 = tail call i32 @strcpy(i8* %44, i8* %1)
%52 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %68, label %54
54: ; preds = %50
%55 = icmp eq i32 %37, 1
%56 = sub nsw i32 %19, %37
%57 = icmp sgt i32 %56, 3
%58 = select i1 %55, i1 true, i1 %57
%59 = load i8*, i8** %2
br i1 %58, label %60, label %64
60: ; preds = %54
%61 = tail call i32 @strcat(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%62 = load i8*, i8** %2
%63 = tail call i32 @strcat(i8* %62, i8* %0)
br label %68
64: ; preds = %54
%65 = sext i32 %37 to i64
%66 = getelementptr inbounds i8, i8* %59, i64 %65
%67 = tail call i32 @strcpy(i8* %66, i8* %0)
br label %68
68: ; preds = %60, %64, %50, %10, %3, %24
ret void
}