#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ parse_input_word_format(char *);
scalar_t__ parse_output_word_format(char const *);
int /*<<< orphan*/ stderr;
char *strchr(char const *, char);
char *strndup(char const *, int);
char *strrchr(char const *, char);
void default_formats(const char *argv0) {
  int bad = 0;
  const char *basename;
  const char *two;
  char *first;
  basename = strrchr(argv0, '/');
  if (basename == NULL)
    basename = argv0;
  else
    basename++;
  two = strchr(basename, '2');
  if (two == NULL)
    return;
  first = strndup(basename, two - basename);
  if (first == NULL) {
    fprintf(stderr, "out of memory\n");
    exit(1);
  }
  if (parse_input_word_format(first))
    bad = 1;
  if (parse_output_word_format(two + 1))
    bad = 1;
  free(first);
  if (bad) {
    fprintf(stderr, "%s: unrecognised word format in executable name\n", argv0);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<default_formats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bd <default_formats+0x3d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11c9 <default_formats+0x49>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x32,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11eb <default_formats+0x6b>
jmp    12a1 <default_formats+0x121>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%esi
call   1070 <strndup@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1231 <default_formats+0xb1>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1060 <parse_input_word_format@plt>
cmp    $0x0,%rax
je     124b <default_formats+0xcb>
movl   $0x1,-0xc(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1090 <parse_output_word_format@plt>
cmp    $0x0,%rax
je     1269 <default_formats+0xe9>
movl   $0x1,-0xc(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0xc(%rbp)
je     12a1 <default_formats+0x121>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<default_formats>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x2f,%esi
call   1050 <strrchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
cmove  %r14,%rbx
mov    %rbx,%rdi
mov    $0x32,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f2 <default_formats+0x72>
mov    %rax,%r15
mov    %r15d,%esi
sub    %ebx,%esi
mov    %rbx,%rdi
call   1070 <strndup@plt>
test   %rax,%rax
je     11fc <default_formats+0x7c>
mov    %rax,%r13
mov    %rax,%rdi
call   1060 <parse_input_word_format@plt>
mov    %rax,%r12
add    $0x1,%r15
mov    %r15,%rdi
call   1090 <parse_output_word_format@plt>
mov    %rax,%rbx
mov    %r13,%rdi
call   1030 <free@plt>
or     %r12,%rbx
jne    121d <default_formats+0x9d>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xde2(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [49 x i8] c"%s: unrecognised word format in executable name\0A\00"
define void @default_formats(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%7 = load i8*, i8** %2
%8 = call i8* @strrchr(i8* %7, i8 signext 47)
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i8*, i8** %2
store i8* %12, i8** %4
br label %16
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %16
16: ; preds = %13, %11
%17 = load i8*, i8** %4
%18 = call i8* @strchr(i8* %17, i8 signext 50)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
br label %58
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = load i8*, i8** %5
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i8* @strndup(i8* %23, i32 %29)
store i8* %30, i8** %6
%31 = load i8*, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %22
%38 = load i8*, i8** %6
%39 = call i64 @parse_input_word_format(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
store i32 1, i32* %3
br label %42
42: ; preds = %41, %37
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = call i64 @parse_output_word_format(i8* %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %42
store i32 1, i32* %3
br label %48
48: ; preds = %47, %42
%49 = load i8*, i8** %6
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %3
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %48
%54 = load i32, i32* @stderr
%55 = load i8*, i8** %2
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %21, %48
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
@.str.1 = [49 x i8] c"%s: unrecognised word format in executable name\0A\00"
define void @default_formats(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%3 = icmp eq i8* %2, null
%4 = getelementptr inbounds i8, i8* %2, i64 1
%5 = select i1 %3, i8* %0, i8* %4
%6 = tail call i8* @strchr(i8* dereferenceable(1) %5, i8 signext 50)
%7 = icmp eq i8* %6, null
br i1 %7, label %31, label %8
8: ; preds = %1
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %5 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = tail call i8* @strndup(i8* %5, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %8
%20 = tail call i64 @parse_input_word_format(i8* %13)
%21 = icmp eq i64 %20, 0
%22 = getelementptr inbounds i8, i8* %6, i64 1
%23 = tail call i64 @parse_output_word_format(i8* %22)
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i1 %21, i1 false
%26 = tail call i32 @free(i8* %13)
br i1 %25, label %31, label %27
27: ; preds = %19
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = tail call i32 @exit(i32 1)
unreachable
31: ; preds = %19, %1
ret void
}