#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 */
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strdup(char *);
scalar_t__ strlen(char *);
char *strrchr(char *, char);
char *make_outfilename(char *infile, char *ext) {
  char *outfile;
  char *p;
  if (strcmp(infile, "-") == 0) {
    return strdup("-");
  }
  outfile = (char *)malloc(strlen(infile) + strlen(ext) + 5);
  if (!outfile) {
    return NULL;
  }
  strcpy(outfile, infile);
  p = strrchr(outfile, '.');
  if (p) {
    *p = 0;
  }
  strcat(outfile, ext);
  if (strcmp(infile, outfile) == 0) {
    strcpy(outfile, infile);
    strcat(outfile, "-out");
  }
  return outfile;
}


x86 assembly (clang, -O0):
<make_outfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11af <make_outfilename+0x3f>
lea    0xe5f(%rip),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    126b <make_outfilename+0xfb>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x5,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <make_outfilename+0x81>
movq   $0x0,-0x8(%rbp)
jmp    126b <make_outfilename+0xfb>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1222 <make_outfilename+0xb2>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1263 <make_outfilename+0xf3>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xda4(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_outfilename>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe7e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <make_outfilename+0x9b>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x5,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     121c <make_outfilename+0xac>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11d4 <make_outfilename+0x64>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    121e <make_outfilename+0xae>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe01(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
jmp    121e <make_outfilename+0xae>
lea    0xdee(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <strdup@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [5 x i8] c"-out\00"
define i8* @make_outfilename(i8* %0, i8* %1) {
%3 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %27
7: ; preds = %2
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%10 = add i64 %8, 5
%11 = add i64 %10, %9
%12 = tail call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %27, label %15
15: ; preds = %7
%16 = tail call i32 @strcpy(i8* %13, i8* %0)
%17 = tail call i8* @strrchr(i8* %13, i8 signext 46)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
store i8 0, i8* %17
br label %20
20: ; preds = %19, %15
%21 = tail call i32 @strcat(i8* %13, i8* %1)
%22 = tail call i64 @strcmp(i8* %0, i8* %13)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @strcpy(i8* %13, i8* %0)
%26 = tail call i32 @strcat(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %20, %24, %7, %5
%28 = phi i8* [ %6, %5 ], [ null, %7 ], [ %13, %24 ], [ %13, %20 ]
ret i8* %28
}