#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 *strchr(char const *, char);
scalar_t__ strcmp(char *, char const *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int dos_namecmp(const char *sname, const char *name, const char *ext) {
  char fname[9], fext[4], *p;
  strncpy(fname, sname, 8);
  if ((p = strchr(fname, '.')))
    *p = '\0';
  strncat(fname, "        ", 8 - strlen(fname));
  fname[9] = '\0';
  if ((p = strchr(sname, '.')))
    strncpy(fext, p, 3);
  else
    fext[0] = fext[1] = fext[2] = ' ';
  fext[4] = '\0';
  return (strcmp(fname, name) && strcmp(fext, ext));
}


x86 assembly (clang, -O0):
<dos_namecmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x21(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1199 <dos_namecmp+0x49>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x21(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x21(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    $0x8,%edx
sub    %rax,%rdx
lea    0xe43(%rip),%rsi
call   1060 <strncat@plt>
movb   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11f9 <dos_namecmp+0xa9>
lea    -0x25(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
jmp    1205 <dos_namecmp+0xb5>
movb   $0x20,-0x23(%rbp)
movb   $0x20,-0x24(%rbp)
movb   $0x20,-0x25(%rbp)
movb   $0x0,-0x21(%rbp)
lea    -0x21(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x39(%rbp)
je     123f <dos_namecmp+0xef>
lea    -0x25(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dos_namecmp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xf(%rsp),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     118e <dos_namecmp+0x3e>
movb   $0x0,(%rax)
lea    0xf(%rsp),%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    $0x8,%edx
sub    %rax,%rdx
lea    0xe56(%rip),%rsi
mov    %r12,%rdi
call   1060 <strncat@plt>
movb   $0x0,0x18(%rsp)
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11dd <dos_namecmp+0x8d>
lea    0xb(%rsp),%rdi
mov    %rax,%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
jmp    11e9 <dos_namecmp+0x99>
movb   $0x20,0xd(%rsp)
movw   $0x2020,0xb(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     121a <dos_namecmp+0xca>
lea    0xb(%rsp),%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    121c <dos_namecmp+0xcc>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c" \00"
define i32 @dos_namecmp(i8* %0, i8* %1, i8* %2) {
%4 = alloca [9 x i8]
%5 = alloca [4 x i8]
%6 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%8 = call i32 @strncpy(i8* %6, i8* %0, i32 8)
%9 = call i8* @strchr(i8* %6, i8 signext 46)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %3
store i8 0, i8* %9
br label %12
12: ; preds = %11, %3
%13 = call i64 @strlen(i8* %6)
%14 = sub nsw i64 8, %13
%15 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %14)
%16 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 9
store i8 0, i8* %16
%17 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 46)
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %12
%20 = call i32 @strncpy(i8* %7, i8* %17, i32 3)
br label %24
21: ; preds = %12
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
store i8 32, i8* %22
%23 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
store i8 32, i8* %23
store i8 32, i8* %7
br label %24
24: ; preds = %21, %19
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 4
store i8 0, i8* %25
%26 = call i64 @strcmp(i8* %6, i8* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %24
%29 = call i64 @strcmp(i8* %7, i8* %2)
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %28, %24
%33 = phi i32 [ 0, %24 ], [ %31, %28 ]
ret i32 %33
}