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


x86 assembly (clang, -O0):
<get_obj>:
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     11ac <get_obj+0x4c>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
xor    $0xffffffff,%eax
cmp    $0x0,%eax
je     11ac <get_obj+0x4c>
mov    -0x18(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    124f <get_obj+0xef>
cmpq   $0x0,-0x20(%rbp)
je     1234 <get_obj+0xd4>
mov    -0x20(%rbp),%rdi
call   1040 <remove_extenstion@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <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    1207 <get_obj+0xa7>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
movq   $0x0,-0x8(%rbp)
jmp    125a <get_obj+0xfa>
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
add    $0x3,%edx
lea    0xe04(%rip),%rsi
call   1060 <strncat@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    124a <get_obj+0xea>
lea    0xde4(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    124f <get_obj+0xef>
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_obj>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbx
test   %rsi,%rsi
je     117c <get_obj+0x1c>
mov    %rsi,%rdi
call   1080 <strdup@plt>
mov    %rax,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %rdx,%rdx
je     11bb <get_obj+0x5b>
mov    %rdx,%rdi
call   1040 <remove_extenstion@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    $0x3,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     11c4 <get_obj+0x64>
lea    0xe75(%rip),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1060 <strncat@plt>
jmp    1174 <get_obj+0x14>
lea    0xe5d(%rip),%rdi
jmp    116f <get_obj+0xf>
lea    0xe35(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1177 <get_obj+0x17>

LLVM IR (-O0):
@.str = [31 x i8] c"error: couldn't realloc string\00"
@.str.1 = [3 x i8] c".o\00"
@.str.2 = [8 x i8] c"a.out.o\00"
define i8* @get_obj(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, 4
%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 %51
24: ; preds = %15, %4
%25 = load i8*, i8** %8
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %47
27: ; preds = %24
%28 = load i8*, i8** %8
%29 = call i8* @remove_extenstion(i8* %28)
store i8* %29, i8** %10
%30 = load i8*, i8** %10
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %11
%32 = load i8*, i8** %10
%33 = load i32, i32* %11
%34 = add nsw i32 %33, 3
%35 = call i8* @realloc(i8* %32, i32 %34)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %27
%39 = call i32 @puts(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %5
br label %54
40: ; preds = %27
%41 = load i8*, i8** %12
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 3
%45 = call i8* @strncat(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = load i8**, i8*** %9
store i8* %45, i8** %46
br label %50
47: ; preds = %24
%48 = call i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%49 = load i8**, i8*** %9
store i8* %48, i8** %49
br label %50
50: ; preds = %47, %40
br label %51
51: ; preds = %50, %20
%52 = load i8**, i8*** %9
%53 = load i8*, i8** %52
store i8* %53, i8** %5
br label %54
54: ; preds = %51, %38
%55 = load i8*, i8** %5
ret i8* %55
}

LLVM IR (-O2):
@.str = [31 x i8] c"error: couldn't realloc string\00"
@.str.1 = [3 x i8] c".o\00"
@.str.2 = [8 x i8] c"a.out.o\00"
define i8* @get_obj(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)
store i8* %7, i8** %3
br label %22
8: ; preds = %4
%9 = icmp eq i8* %2, null
br i1 %9, label %20, label %10
10: ; preds = %8
%11 = tail call i8* @remove_extenstion(i8* %2)
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 3
%14 = tail call i8* @realloc(i8* %11, i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %18, label %16
16: ; preds = %10
%17 = tail call i8* @strncat(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i8* %17, i8** %3
br label %22
18: ; preds = %10
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %22
20: ; preds = %8
%21 = tail call dereferenceable_or_null(8) i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %3
br label %22
22: ; preds = %6, %20, %16, %18
%23 = phi i8* [ null, %18 ], [ %17, %16 ], [ %21, %20 ], [ %7, %6 ]
ret i8* %23
}