#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__ FILENAME_CMPN(char *, char *, int);
int /*<<< orphan*/ filename_non_directory(char *);
scalar_t__ isdigit(char);
int strlen(char *);
char *xstrdup(int /*<<< orphan*/);
char *program_name_from_file_name(char *file_name) {
  int i;
  char *program_name = xstrdup(filename_non_directory(file_name));
  for (i = strlen(program_name) - 1; i > 0; i--)
    if (program_name[i] == '.' &&
        (FILENAME_CMPN(program_name + i, ".info", 5) == 0 ||
         FILENAME_CMPN(program_name + i, ".inf", 4) == 0 ||
         isdigit(program_name[i + 1]))) {
      program_name[i] = 0;
      break;
    }
  return program_name;
}


x86 assembly (clang, -O0):
<program_name_from_file_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <filename_non_directory@plt>
mov    %eax,%edi
call   1060 <xstrdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    122e <program_name_from_file_name+0xde>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    121b <program_name_from_file_name+0xcb>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe50(%rip),%rsi
mov    $0x5,%edx
call   1050 <FILENAME_CMPN@plt>
cmp    $0x0,%rax
je     120a <program_name_from_file_name+0xba>
mov    -0x18(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe30(%rip),%rsi
mov    $0x4,%edx
call   1050 <FILENAME_CMPN@plt>
cmp    $0x0,%rax
je     120a <program_name_from_file_name+0xba>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     121b <program_name_from_file_name+0xcb>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    122e <program_name_from_file_name+0xde>
jmp    1220 <program_name_from_file_name+0xd0>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    117f <program_name_from_file_name+0x2f>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<program_name_from_file_name>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
call   1070 <filename_non_directory@plt>
mov    %eax,%edi
call   1060 <xstrdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11e7 <program_name_from_file_name+0x97>
mov    %eax,%ebx
add    $0x1,%rbx
lea    0xe7e(%rip),%r14
lea    0xe7d(%rip),%r15
jmp    119a <program_name_from_file_name+0x4a>
nopl   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
jbe    11e7 <program_name_from_file_name+0x97>
lea    -0x2(%rbx),%r13d
cmpb   $0x2e,(%r12,%r13,1)
jne    1190 <program_name_from_file_name+0x40>
add    %r12,%r13
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <FILENAME_CMPN@plt>
test   %rax,%rax
je     11e2 <program_name_from_file_name+0x92>
mov    %r13,%rdi
mov    %r15,%rsi
mov    $0x4,%edx
call   1050 <FILENAME_CMPN@plt>
test   %rax,%rax
je     11e2 <program_name_from_file_name+0x92>
movsbl -0x1(%r12,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1190 <program_name_from_file_name+0x40>
movb   $0x0,0x0(%r13)
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c".info\00"
@.str.1 = [5 x i8] c".inf\00"
define i8* @program_name_from_file_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @filename_non_directory(i8* %5)
%7 = call i8* @xstrdup(i32 %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %3
br label %11
11: ; preds = %51, %1
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %54
14: ; preds = %11
%15 = load i8*, i8** %4
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %50
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = call i64 @FILENAME_CMPN(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %45, label %29
29: ; preds = %22
%30 = load i8*, i8** %4
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = call i64 @FILENAME_CMPN(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%35 = icmp eq i64 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %29
%37 = load i8*, i8** %4
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8, i8* %41
%43 = call i64 @isdigit(i8 signext %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %36, %29, %22
%46 = load i8*, i8** %4
%47 = load i32, i32* %3
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
br label %54
50: ; preds = %36, %14
br label %51
51: ; preds = %50
%52 = load i32, i32* %3
%53 = add nsw i32 %52, -1
store i32 %53, i32* %3
br label %11
54: ; preds = %45, %11
%55 = load i8*, i8** %4
ret i8* %55
}

LLVM IR (-O2):
@.str = [6 x i8] c".info\00"
@.str.1 = [5 x i8] c".inf\00"
define i8* @program_name_from_file_name(i8* %0) {
%2 = tail call i32 @filename_non_directory(i8* %0)
%3 = tail call i8* @xstrdup(i32 %2)
%4 = tail call i32 @strlen(i8* %3)
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %29
6: ; preds = %1
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %27
%9 = phi i64 [ %7, %6 ], [ %10, %27 ]
%10 = add nsw i64 %9, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %3, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %27
15: ; preds = %8
%16 = tail call i64 @FILENAME_CMPN(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %15
%19 = tail call i64 @FILENAME_CMPN(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %3, i64 %9
%23 = load i8, i8* %22
%24 = tail call i64 @isdigit(i8 signext %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21, %18, %15
store i8 0, i8* %12
br label %29
27: ; preds = %8, %21
%28 = icmp ugt i64 %9, 2
br i1 %28, label %8, label %29
29: ; preds = %27, %1, %26
ret i8* %3
}