#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__ isalnum(char const);
int /*<<< orphan*/ nasm_stricmp(char const *, char *);
char *strchr(char const *, char);
const char *getformat(const char *pathname) {
  const char *p;
  static char fmt_buf[16];
  for (p = strchr(pathname, '\0') - 1; p >= pathname; p--) {
    if (!nasm_stricmp(p, "rdf2")) {
      const char *q = p + 4;
      char *r = fmt_buf;
      while (isalnum(*q) && r < fmt_buf + sizeof fmt_buf - 1)
        *r++ = *q++;
      *r = '\0';
      if (fmt_buf[0])
        return fmt_buf;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getformat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <strchr@plt>
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jb     1236 <getformat+0x106>
mov    -0x18(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1030 <nasm_stricmp@plt>
cmp    $0x0,%eax
jne    1220 <getformat+0xf0>
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
lea    0x2ec7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalnum@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
je     11c0 <getformat+0x90>
lea    0x2e9e(%rip),%rax
add    $0xf,%rax
cmp    %rax,-0x28(%rbp)
setb   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11d0 <getformat+0xa0>
jmp    11f7 <getformat+0xc7>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    118d <getformat+0x5d>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
cmpb   $0x0,0x2e4b(%rip)
je     121b <getformat+0xeb>
lea    0x2e3e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    123e <getformat+0x10e>
jmp    1220 <getformat+0xf0>
jmp    1225 <getformat+0xf5>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    114f <getformat+0x1f>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getformat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1040 <strlen@plt>
lea    (%rax,%rbp,1),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rbp,%rcx
jae    1165 <getformat+0x35>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    (%rax,%rbp,1),%rbx
lea    (%rax,%rbp,1),%r15
add    $0x4,%r15
lea    0x2ed8(%rip),%r14
lea    0x2ee0(%rip),%r12
mov    %rbp,(%rsp)
jmp    11b4 <getformat+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
movb   $0x0,(%r14)
cmpb   $0x0,0x2eb5(%rip)
mov    %rbp,%r14
mov    (%rsp),%rbp
jne    1153 <getformat+0x23>
lea    -0x1(%r13),%rcx
add    $0xffffffffffffffff,%r15
mov    %r13,%rbx
cmp    %rbp,%rcx
jb     1150 <getformat+0x20>
mov    %rcx,%r13
mov    %rcx,%rdi
lea    0xe3f(%rip),%rsi
call   1030 <nasm_stricmp@plt>
test   %eax,%eax
jne    11a4 <getformat+0x74>
movsbl 0x3(%rbx),%edi
call   1050 <isalnum@plt>
mov    %r14,%rbp
test   %rax,%rax
je     1190 <getformat+0x60>
mov    %r15,%rbx
mov    %rbp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%eax
mov    %al,(%r14)
add    $0x1,%r14
movsbl (%rbx),%edi
call   1050 <isalnum@plt>
test   %rax,%rax
je     1190 <getformat+0x60>
add    $0x1,%rbx
cmp    %r12,%r14
jb     11f0 <getformat+0xc0>
jmp    1190 <getformat+0x60>

LLVM IR (-O0):
@getformat.fmt_buf = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"rdf2\00"
define i8* @getformat(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i8* @strchr(i8* %7, i8 signext 0)
%9 = getelementptr inbounds i8, i8* %8, i64 -1
store i8* %9, i8** %4
br label %10
10: ; preds = %44, %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = icmp uge i8* %11, %12
br i1 %13, label %14, label %47
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @nasm_stricmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %43, label %18
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 4
store i8* %20, i8** %5
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0), i8** %6
br label %21
21: ; preds = %31, %18
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
%24 = call i64 @isalnum(i8 signext %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %6
%28 = icmp ult i8* %27, getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 1, i64 -1)
br label %29
29: ; preds = %26, %21
%30 = phi i1 [ false, %21 ], [ %28, %26 ]
br i1 %30, label %31, label %37
31: ; preds = %29
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = load i8, i8* %32
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %6
store i8 %34, i8* %35
br label %21
37: ; preds = %29
%38 = load i8*, i8** %6
store i8 0, i8* %38
%39 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0)
%40 = icmp ne i8 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0), i8** %2
br label %48
42: ; preds = %37
br label %43
43: ; preds = %42, %14
br label %44
44: ; preds = %43
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %4
br label %10
47: ; preds = %10
store i8* null, i8** %2
br label %48
48: ; preds = %47, %41
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
@getformat.fmt_buf = internal global [16 x i8] zeroinitializer
@.str = [5 x i8] c"rdf2\00"
define i8* @getformat(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = getelementptr i8, i8* %0, i64 %2
%4 = getelementptr inbounds i8, i8* %3, i64 -1
%5 = icmp ult i8* %4, %0
br i1 %5, label %34, label %6
6: ; preds = %1, %31
%7 = phi i8* [ %32, %31 ], [ %4, %1 ]
%8 = phi i8* [ %7, %31 ], [ %3, %1 ]
%9 = tail call i32 @nasm_stricmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %8, i64 3
%13 = load i8, i8* %12
%14 = tail call i64 @isalnum(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %11, %16
%17 = phi i8* [ %21, %16 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0), %11 ]
%18 = phi i8* [ %19, %16 ], [ %12, %11 ]
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %18
%21 = getelementptr inbounds i8, i8* %17, i64 1
store i8 %20, i8* %17
%22 = load i8, i8* %19
%23 = tail call i64 @isalnum(i8 signext %22)
%24 = icmp ne i64 %23, 0
%25 = icmp ult i8* %21, getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 15)
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %16, label %27
27: ; preds = %16, %11
%28 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0), %11 ], [ %21, %16 ]
store i8 0, i8* %28
%29 = load i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0)
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %6, %27
%32 = getelementptr inbounds i8, i8* %7, i64 -1
%33 = icmp ult i8* %32, %0
br i1 %33, label %34, label %6
34: ; preds = %27, %31, %1
%35 = phi i8* [ null, %1 ], [ null, %31 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @getformat.fmt_buf, i64 0, i64 0), %27 ]
ret i8* %35
}