#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(int /*<<< orphan*/ *);
char *realloc(char *, int);
char *remove_extenstion(char const *);
int /*<<< orphan*/ stderr;
char *strdup(char const *);
int strlen(char *);
char *strncat(char *, char *, int);
char *get_as(int mode, const char *name, const char *original, char **ret) {
  if (name != NULL && ~(mode & (1 << 1)))
    *ret = strdup(name);
  else if (mode & (1 << 3))
    *ret = NULL;
  else if (original != NULL) {
    char *base = remove_extenstion(original);
    int strl = strlen(base);
    char *new_base = realloc(base, strl + 3);
    if (new_base == NULL) {
      fprintf(stderr, "error: couldn't realloc string: ");
      perror(NULL);
      return (*ret = NULL);
    }
    base = new_base;
    *ret = strncat(base, ".s", strl + 3);
  } else
    *ret = strdup("a.out.s");
  return *ret;
}


x86 assembly (clang, -O0):
<get_as>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11bc <get_as+0x4c>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
xor    $0xffffffff,%eax
cmp    $0x0,%eax
je     11bc <get_as+0x4c>
mov    -0x18(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    12a0 <get_as+0x130>
mov    -0xc(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11db <get_as+0x6b>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
jmp    129b <get_as+0x12b>
cmpq   $0x0,-0x20(%rbp)
je     1280 <get_as+0x110>
mov    -0x20(%rbp),%rdi
call   1030 <remove_extenstion@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
add    $0x3,%esi
call   1070 <realloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1253 <get_as+0xe3>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <perror@plt>
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    12ab <get_as+0x13b>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
add    $0x3,%edx
lea    0xdba(%rip),%rsi
call   1050 <strncat@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1296 <get_as+0x126>
lea    0xd9a(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    129b <get_as+0x12b>
jmp    12a0 <get_as+0x130>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_as>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
test   %rsi,%rsi
je     1194 <get_as+0x24>
mov    %rsi,%rdi
call   1090 <strdup@plt>
mov    %rax,%rbx
mov    %rbx,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
test   $0x8,%dil
jne    11d9 <get_as+0x69>
test   %rdx,%rdx
je     11dd <get_as+0x6d>
mov    %rdx,%rdi
call   1030 <remove_extenstion@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
add    $0x3,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     11e6 <get_as+0x76>
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1050 <strncat@plt>
jmp    1185 <get_as+0x15>
xor    %ebx,%ebx
jmp    1188 <get_as+0x18>
lea    0xe3d(%rip),%rdi
jmp    1180 <get_as+0x10>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
xor    %ebx,%ebx
xor    %edi,%edi
call   1080 <perror@plt>
jmp    1188 <get_as+0x18>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"error: couldn't realloc string: \00"
@.str.1 = [3 x i8] c".s\00"
@.str.2 = [8 x i8] c"a.out.s\00"
define i8* @get_as(i32 %0, i8* %1, i8* %2, i8** %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %24
15: ; preds = %4
%16 = load i32, i32* %6
%17 = and i32 %16, 2
%18 = xor i32 %17, -1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %7
%22 = call i8* @strdup(i8* %21)
%23 = load i8**, i8*** %9
store i8* %22, i8** %23
br label %61
24: ; preds = %15, %4
%25 = load i32, i32* %6
%26 = and i32 %25, 8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i8**, i8*** %9
store i8* null, i8** %29
br label %60
30: ; preds = %24
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %56
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = call i8* @remove_extenstion(i8* %34)
store i8* %35, i8** %10
%36 = load i8*, i8** %10
%37 = call i32 @strlen(i8* %36)
store i32 %37, i32* %11
%38 = load i8*, i8** %10
%39 = load i32, i32* %11
%40 = add nsw i32 %39, 3
%41 = call i8* @realloc(i8* %38, i32 %40)
store i8* %41, i8** %12
%42 = load i8*, i8** %12
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %49
44: ; preds = %33
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%47 = call i32 @perror(i32* null)
%48 = load i8**, i8*** %9
store i8* null, i8** %48
store i8* null, i8** %5
br label %64
49: ; preds = %33
%50 = load i8*, i8** %12
store i8* %50, i8** %10
%51 = load i8*, i8** %10
%52 = load i32, i32* %11
%53 = add nsw i32 %52, 3
%54 = call i8* @strncat(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %53)
%55 = load i8**, i8*** %9
store i8* %54, i8** %55
br label %59
56: ; preds = %30
%57 = call i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%58 = load i8**, i8*** %9
store i8* %57, i8** %58
br label %59
59: ; preds = %56, %49
br label %60
60: ; preds = %59, %28
br label %61
61: ; preds = %60, %20
%62 = load i8**, i8*** %9
%63 = load i8*, i8** %62
store i8* %63, i8** %5
br label %64
64: ; preds = %61, %44
%65 = load i8*, i8** %5
ret i8* %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"error: couldn't realloc string: \00"
@.str.1 = [3 x i8] c".s\00"
@.str.2 = [8 x i8] c"a.out.s\00"
define i8* @get_as(i32 %0, i8* %1, i8* %2, i8** nocapture %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i8* @strdup(i8* %1)
br label %27
8: ; preds = %4
%9 = and i32 %0, 8
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8
%12 = icmp eq i8* %2, null
br i1 %12, label %25, label %13
13: ; preds = %11
%14 = tail call i8* @remove_extenstion(i8* %2)
%15 = tail call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 3
%17 = tail call i8* @realloc(i8* %14, i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %13
%20 = tail call i8* @strncat(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %27
21: ; preds = %13
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%24 = tail call i32 @perror(i32* null)
br label %27
25: ; preds = %11
%26 = tail call dereferenceable_or_null(8) i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %27
27: ; preds = %8, %6, %25, %19, %21
%28 = phi i8* [ %7, %6 ], [ %26, %25 ], [ %20, %19 ], [ null, %21 ], [ null, %8 ]
store i8* %28, i8** %3
ret i8* %28
}