#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 autostart_autodetect(char const *, char *, unsigned int, unsigned int);
int /*<<< orphan*/ charset_petconvstring(unsigned char *, int /*<<< orphan*/);
char *charset_replace_hexcodes(char *);
int /*<<< orphan*/ lib_free(char *);
char *lib_stralloc(char const *);
char *strrchr(char const *, char);
scalar_t__ util_file_exists(char *);
int autostart_autodetect_opt_prgname(const char *file_prog_name,
                                     unsigned int alt_prg_number,
                                     unsigned int runmode) {
  char *tmp;
  int result;
  tmp = strrchr(file_prog_name, ':');
  if (tmp) {
    char *autostart_prg_name;
    char *autostart_file;
    autostart_file = lib_stralloc(file_prog_name);
    autostart_prg_name = strrchr(autostart_file, ':');
    *autostart_prg_name++ = '\0';
    if (util_file_exists(autostart_file)) {
      char *name;
      charset_petconvstring((unsigned char *)autostart_prg_name, 0);
      name = charset_replace_hexcodes(autostart_prg_name);
      result = autostart_autodetect(autostart_file, name, 0, runmode);
      lib_free(name);
    } else {
      result =
          autostart_autodetect(file_prog_name, NULL, alt_prg_number, runmode);
    }
    lib_free(autostart_file);
  } else {
    result =
        autostart_autodetect(file_prog_name, NULL, alt_prg_number, runmode);
  }
  return result;
}


x86 assembly (clang, -O0):
<autostart_autodetect_opt_prgname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1242 <autostart_autodetect_opt_prgname+0xd2>
mov    -0x8(%rbp),%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1060 <util_file_exists@plt>
cmp    $0x0,%rax
je     121e <autostart_autodetect_opt_prgname+0xae>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
call   1080 <charset_petconvstring@plt>
mov    -0x28(%rbp),%rdi
call   1090 <charset_replace_hexcodes@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x10(%rbp),%ecx
xor    %edx,%edx
call   1070 <autostart_autodetect@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <lib_free@plt>
jmp    1234 <autostart_autodetect_opt_prgname+0xc4>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <autostart_autodetect@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <lib_free@plt>
jmp    1258 <autostart_autodetect_opt_prgname+0xe8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <autostart_autodetect@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<autostart_autodetect_opt_prgname>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%rbp
mov    $0x3a,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11f0 <autostart_autodetect_opt_prgname+0x80>
mov    %rbp,%rdi
call   1030 <lib_stralloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    $0x3a,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r12,%rdi
call   1060 <util_file_exists@plt>
test   %rax,%rax
je     1208 <autostart_autodetect_opt_prgname+0x98>
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <charset_petconvstring@plt>
mov    %rbx,%rdi
call   1090 <charset_replace_hexcodes@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    %rax,%rsi
xor    %edx,%edx
mov    %r14d,%ecx
call   1070 <autostart_autodetect@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <lib_free@plt>
jmp    121a <autostart_autodetect_opt_prgname+0xaa>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <autostart_autodetect@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1070 <autostart_autodetect@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <lib_free@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @autostart_autodetect_opt_prgname(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = call i8* @strrchr(i8* %12, i8 signext 58)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %45
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call i8* @lib_stralloc(i8* %17)
store i8* %18, i8** %10
%19 = load i8*, i8** %10
%20 = call i8* @strrchr(i8* %19, i8 signext 58)
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %9
store i8 0, i8* %21
%23 = load i8*, i8** %10
%24 = call i64 @util_file_exists(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %16
%27 = load i8*, i8** %9
%28 = call i32 @charset_petconvstring(i8* %27, i32 0)
%29 = load i8*, i8** %9
%30 = call i8* @charset_replace_hexcodes(i8* %29)
store i8* %30, i8** %11
%31 = load i8*, i8** %10
%32 = load i8*, i8** %11
%33 = load i32, i32* %6
%34 = call i32 @autostart_autodetect(i8* %31, i8* %32, i32 0, i32 %33)
store i32 %34, i32* %8
%35 = load i8*, i8** %11
%36 = call i32 @lib_free(i8* %35)
br label %42
37: ; preds = %16
%38 = load i8*, i8** %4
%39 = load i32, i32* %5
%40 = load i32, i32* %6
%41 = call i32 @autostart_autodetect(i8* %38, i8* null, i32 %39, i32 %40)
store i32 %41, i32* %8
br label %42
42: ; preds = %37, %26
%43 = load i8*, i8** %10
%44 = call i32 @lib_free(i8* %43)
br label %50
45: ; preds = %3
%46 = load i8*, i8** %4
%47 = load i32, i32* %5
%48 = load i32, i32* %6
%49 = call i32 @autostart_autodetect(i8* %46, i8* null, i32 %47, i32 %48)
store i32 %49, i32* %8
br label %50
50: ; preds = %45, %42
%51 = load i32, i32* %8
ret i32 %51
}

LLVM IR (-O2):
define i32 @autostart_autodetect_opt_prgname(i8* %0, i32 %1, i32 %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 58)
%5 = icmp eq i8* %4, null
br i1 %5, label %22, label %6
6: ; preds = %3
%7 = tail call i8* @lib_stralloc(i8* %0)
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %7, i8 signext 58)
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 0, i8* %8
%10 = tail call i64 @util_file_exists(i8* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = tail call i32 @charset_petconvstring(i8* %9, i32 0)
%14 = tail call i8* @charset_replace_hexcodes(i8* %9)
%15 = tail call i32 @autostart_autodetect(i8* %7, i8* %14, i32 0, i32 %2)
%16 = tail call i32 @lib_free(i8* %14)
br label %19
17: ; preds = %6
%18 = tail call i32 @autostart_autodetect(i8* %0, i8* null, i32 %1, i32 %2)
br label %19
19: ; preds = %17, %12
%20 = phi i32 [ %15, %12 ], [ %18, %17 ]
%21 = tail call i32 @lib_free(i8* %7)
br label %24
22: ; preds = %3
%23 = tail call i32 @autostart_autodetect(i8* %0, i8* null, i32 %1, i32 %2)
br label %24
24: ; preds = %22, %19
%25 = phi i32 [ %20, %19 ], [ %23, %22 ]
ret i32 %25
}