#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*/ nasm_error(int, char *, ...);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void standard_extension(char *inname, char *outname, char *extension) {
  char *p, *q;
  if (*outname)
    return;
  q = inname;
  p = outname;
  while (*q)
    *p++ = *q++;
  *p = '\0';
  while (p > outname && *--p != '.')
    ;
  if (*p != '.')
    while (*p)
      p++;
  if (!strcmp(p, extension)) {
    if (*extension)
      nasm_error(0x00000000 | 0x00000010,
                 "file name already ends in `%s': "
                 "output will be in `nasm.out'",
                 extension);
    else
      nasm_error(0x00000000 | 0x00000010, "file name already has no extension: "
                                          "output will be in `nasm.out'");
    strcpy(outname, "nasm.out");
  } else
    strcpy(p, extension);
}


x86 assembly (clang, -O0):
<standard_extension>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1156 <standard_extension+0x26>
jmp    1291 <standard_extension+0x161>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119a <standard_extension+0x6a>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1166 <standard_extension+0x36>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x29(%rbp)
jbe    11d0 <standard_extension+0xa0>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x20(%rbp)
movsbl -0x1(%rax),%eax
cmp    $0x2e,%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11e0 <standard_extension+0xb0>
jmp    11e5 <standard_extension+0xb5>
jmp    11a1 <standard_extension+0x71>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     121d <standard_extension+0xed>
jmp    11fa <standard_extension+0xca>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1218 <standard_extension+0xe8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11fa <standard_extension+0xca>
jmp    121d <standard_extension+0xed>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1284 <standard_extension+0x154>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     125c <standard_extension+0x12c>
mov    -0x18(%rbp),%rdx
mov    $0x10,%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1050 <nasm_error@plt>
jmp    126f <standard_extension+0x13f>
mov    $0x10,%edi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1050 <nasm_error@plt>
mov    -0x10(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1291 <standard_extension+0x161>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<standard_extension>:
push   %r15
push   %r14
push   %rbx
cmpb   $0x0,(%rsi)
je     1140 <standard_extension+0x10>
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rdx,%r14
mov    %rsi,%r15
mov    (%rdi),%cl
mov    %rsi,%rax
test   %cl,%cl
je     1171 <standard_extension+0x41>
add    $0x1,%rdi
mov    %r15,%rax
cs nopw 0x0(%rax,%rax,1)
mov    %cl,(%rax)
add    $0x1,%rax
movzbl (%rdi),%ecx
add    $0x1,%rdi
test   %cl,%cl
jne    1160 <standard_extension+0x30>
movb   $0x0,(%rax)
mov    $0x1,%cl
cmp    %r15,%rax
jbe    11ad <standard_extension+0x7d>
add    $0xffffffffffffffff,%rax
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rbx),%ecx
cmp    $0x2e,%cl
je     11cd <standard_extension+0x9d>
lea    -0x1(%rbx),%rax
cmp    %r15,%rbx
mov    %rax,%rbx
ja     1190 <standard_extension+0x60>
test   %cl,%cl
sete   %cl
add    $0x1,%rax
test   %cl,%cl
je     11c0 <standard_extension+0x90>
mov    %rax,%rbx
jmp    11cd <standard_extension+0x9d>
cs nopw 0x0(%rax,%rax,1)
lea    0x1(%rax),%rbx
cmpb   $0x0,0x1(%rax)
mov    %rbx,%rax
jne    11c0 <standard_extension+0x90>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     11e4 <standard_extension+0xb4>
mov    %rbx,%rdi
mov    %r14,%rsi
jmp    121f <standard_extension+0xef>
cmpb   $0x0,(%r14)
je     1202 <standard_extension+0xd2>
lea    0xe0f(%rip),%rsi
mov    $0x10,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <nasm_error@plt>
jmp    1215 <standard_extension+0xe5>
lea    0xe34(%rip),%rsi
mov    $0x10,%edi
xor    %eax,%eax
call   1050 <nasm_error@plt>
lea    0xe62(%rip),%rsi
mov    %r15,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [61 x i8] c"file name already ends in `%s': output will be in `nasm.out'\00"
@.str.1 = [65 x i8] c"file name already has no extension: output will be in `nasm.out'\00"
@.str.2 = [9 x i8] c"nasm.out\00"
define void @standard_extension(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %3
br label %76
13: ; preds = %3
%14 = load i8*, i8** %4
store i8* %14, i8** %8
%15 = load i8*, i8** %5
store i8* %15, i8** %7
br label %16
16: ; preds = %20, %13
%17 = load i8*, i8** %8
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i8*, i8** %8
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %8
%23 = load i8, i8* %21
%24 = load i8*, i8** %7
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %7
store i8 %23, i8* %24
br label %16
26: ; preds = %16
%27 = load i8*, i8** %7
store i8 0, i8* %27
br label %28
28: ; preds = %40, %26
%29 = load i8*, i8** %7
%30 = load i8*, i8** %5
%31 = icmp ugt i8* %29, %30
br i1 %31, label %32, label %38
32: ; preds = %28
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 -1
store i8* %34, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 46
br label %38
38: ; preds = %32, %28
%39 = phi i1 [ false, %28 ], [ %37, %32 ]
br i1 %39, label %40, label %41
40: ; preds = %38
br label %28
41: ; preds = %38
%42 = load i8*, i8** %7
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 46
br i1 %45, label %46, label %55
46: ; preds = %41
br label %47
47: ; preds = %51, %46
%48 = load i8*, i8** %7
%49 = load i8, i8* %48
%50 = icmp ne i8 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %7
br label %47
54: ; preds = %47
br label %55
55: ; preds = %54, %41
%56 = load i8*, i8** %7
%57 = load i8*, i8** %6
%58 = call i32 @strcmp(i8* %56, i8* %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %72, label %60
60: ; preds = %55
%61 = load i8*, i8** %6
%62 = load i8, i8* %61
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i8*, i8** %6
%66 = call i32 (i32, i8*, ...) @nasm_error(i32 16, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %65)
br label %69
67: ; preds = %60
%68 = call i32 (i32, i8*, ...) @nasm_error(i32 16, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
br label %69
69: ; preds = %67, %64
%70 = load i8*, i8** %5
%71 = call i32 @strcpy(i8* %70, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %76
72: ; preds = %55
%73 = load i8*, i8** %7
%74 = load i8*, i8** %6
%75 = call i32 @strcpy(i8* %73, i8* %74)
br label %76
76: ; preds = %12, %72, %69
ret void
}

LLVM IR (-O2):
@.str = [61 x i8] c"file name already ends in `%s': output will be in `nasm.out'\00"
@.str.1 = [65 x i8] c"file name already has no extension: output will be in `nasm.out'\00"
@.str.2 = [9 x i8] c"nasm.out\00"
define void @standard_extension(i8* nocapture %0, i8* %1, i8* %2) {
%4 = load i8, i8* %1
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %52
6: ; preds = %3
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %9
%10 = phi i8 [ %15, %9 ], [ %7, %6 ]
%11 = phi i8* [ %13, %9 ], [ %0, %6 ]
%12 = phi i8* [ %14, %9 ], [ %1, %6 ]
%13 = getelementptr inbounds i8, i8* %11, i64 1
%14 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %10, i8* %12
%15 = load i8, i8* %13
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %6
%18 = phi i8* [ %1, %6 ], [ %14, %9 ]
store i8 0, i8* %18
%19 = icmp ugt i8* %18, %1
br i1 %19, label %22, label %29
20: ; preds = %22
%21 = icmp ugt i8* %24, %1
br i1 %21, label %22, label %27
22: ; preds = %17, %20
%23 = phi i8* [ %24, %20 ], [ %18, %17 ]
%24 = getelementptr inbounds i8, i8* %23, i64 -1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 46
br i1 %26, label %37, label %20
27: ; preds = %20
%28 = icmp eq i8 %25, 0
br label %29
29: ; preds = %27, %17
%30 = phi i1 [ %28, %27 ], [ true, %17 ]
%31 = phi i8* [ %24, %27 ], [ %18, %17 ]
br i1 %30, label %37, label %32
32: ; preds = %29, %32
%33 = phi i8* [ %34, %32 ], [ %31, %29 ]
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %32
37: ; preds = %22, %32, %29
%38 = phi i8* [ %31, %29 ], [ %34, %32 ], [ %24, %22 ]
%39 = tail call i32 @strcmp(i8* %38, i8* dereferenceable(1) %2)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %50
41: ; preds = %37
%42 = load i8, i8* %2
%43 = icmp eq i8 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %41
%45 = tail call i32 (i32, i8*, ...) @nasm_error(i32 16, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %48
46: ; preds = %41
%47 = tail call i32 (i32, i8*, ...) @nasm_error(i32 16, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0))
br label %48
48: ; preds = %46, %44
%49 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %52
50: ; preds = %37
%51 = tail call i32 @strcpy(i8* %38, i8* %2)
br label %52
52: ; preds = %48, %50, %3
ret void
}