#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(int);
int /*<<< orphan*/ myWarn_Loc(int, char *, int, char *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
int fileAllocNewExten(const char *name, const char *ext, char **newName) {
  char *ptr;
  if ((ptr = strrchr(name, '.')) == NULL) {
    *newName = (char *)malloc((strlen(name) + strlen(ext) + 1) * sizeof(char));
    if (*newName == NULL) {
      myWarn_Loc(3,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/brianmckenna/rex2nc/refs/"
                 "heads/master/src/libaat/myutil.c",
                 743, "Ran out of memory\n");
      return -1;
    }
    strcpy(*newName, name);
  } else {
    *newName = (char *)malloc(((ptr - name) + strlen(ext) + 1) * sizeof(char));
    if (*newName == NULL) {
      myWarn_Loc(3,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/brianmckenna/rex2nc/refs/"
                 "heads/master/src/libaat/myutil.c",
                 751, "Ran out of memory\n");
      return -1;
    }
    strncpy(*newName, name, ptr - name);
    (*newName)[ptr - name] = '\0';
  }
  strcat(*newName, ext);
  return 0;
}


x86 assembly (clang, -O0):
<fileAllocNewExten>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1222 <fileAllocNewExten+0xb2>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    120d <fileAllocNewExten+0x9d>
mov    $0x3,%edi
lea    0xe10(%rip),%rsi
mov    $0x2e7,%edx
lea    0xe98(%rip),%rcx
call   1090 <myWarn_Loc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <fileAllocNewExten+0x170>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    12c9 <fileAllocNewExten+0x159>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1296 <fileAllocNewExten+0x126>
mov    $0x3,%edi
lea    0xd87(%rip),%rsi
mov    $0x2ef,%edx
lea    0xe0f(%rip),%rcx
call   1090 <myWarn_Loc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e0 <fileAllocNewExten+0x170>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fileAllocNewExten>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x2e,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     11c7 <fileAllocNewExten+0x57>
mov    %rax,%rbx
sub    %r12,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1206 <fileAllocNewExten+0x96>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbx,1)
jmp    11f7 <fileAllocNewExten+0x87>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1220 <fileAllocNewExten+0xb0>
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    (%r15),%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
xor    %eax,%eax
jmp    1242 <fileAllocNewExten+0xd2>
lea    0xdf3(%rip),%rsi
lea    0xe80(%rip),%rcx
mov    $0x3,%edi
mov    $0x2ef,%edx
jmp    1238 <fileAllocNewExten+0xc8>
lea    0xdd9(%rip),%rsi
lea    0xe66(%rip),%rcx
mov    $0x3,%edi
mov    $0x2e7,%edx
call   1090 <myWarn_Loc@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/brianmckenna/rex2nc/refs/heads/master/src/libaat/myutil.c\00"
@.str.1 = [19 x i8] c"Ran out of memory\0A\00"
define i32 @fileAllocNewExten(i8* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%9 = load i8*, i8** %5
%10 = call i8* @strrchr(i8* %9, i8 signext 46)
store i8* %10, i8** %8
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %35
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %14, %16
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = load i8**, i8*** %7
store i8* %23, i8** %24
%25 = load i8**, i8*** %7
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %12
%29 = call i32 @myWarn_Loc(i32 3, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), i32 743, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %80
30: ; preds = %12
%31 = load i8**, i8*** %7
%32 = load i8*, i8** %31
%33 = load i8*, i8** %5
%34 = call i32 @strcpy(i8* %32, i8* %33)
br label %75
35: ; preds = %3
%36 = load i8*, i8** %8
%37 = load i8*, i8** %5
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = load i8*, i8** %6
%42 = call i32 @strlen(i8* %41)
%43 = sext i32 %42 to i64
%44 = add nsw i64 %40, %43
%45 = add nsw i64 %44, 1
%46 = mul i64 %45, 1
%47 = trunc i64 %46 to i32
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
%50 = load i8**, i8*** %7
store i8* %49, i8** %50
%51 = load i8**, i8*** %7
%52 = load i8*, i8** %51
%53 = icmp eq i8* %52, null
br i1 %53, label %54, label %56
54: ; preds = %35
%55 = call i32 @myWarn_Loc(i32 3, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), i32 751, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %80
56: ; preds = %35
%57 = load i8**, i8*** %7
%58 = load i8*, i8** %57
%59 = load i8*, i8** %5
%60 = load i8*, i8** %8
%61 = load i8*, i8** %5
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = trunc i64 %64 to i32
%66 = call i32 @strncpy(i8* %58, i8* %59, i32 %65)
%67 = load i8**, i8*** %7
%68 = load i8*, i8** %67
%69 = load i8*, i8** %8
%70 = load i8*, i8** %5
%71 = ptrtoint i8* %69 to i64
%72 = ptrtoint i8* %70 to i64
%73 = sub i64 %71, %72
%74 = getelementptr inbounds i8, i8* %68, i64 %73
store i8 0, i8* %74
br label %75
75: ; preds = %56, %30
%76 = load i8**, i8*** %7
%77 = load i8*, i8** %76
%78 = load i8*, i8** %6
%79 = call i32 @strcat(i8* %77, i8* %78)
store i32 0, i32* %4
br label %80
80: ; preds = %75, %54, %28
%81 = load i32, i32* %4
ret i32 %81
}

LLVM IR (-O2):
@.str = [148 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/brianmckenna/rex2nc/refs/heads/master/src/libaat/myutil.c\00"
@.str.1 = [19 x i8] c"Ran out of memory\0A\00"
define i32 @fileAllocNewExten(i8* %0, i8* %1, i8** nocapture %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 46)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = tail call i32 @strlen(i8* %1)
%9 = add i32 %7, 1
%10 = add i32 %9, %8
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %2
%13 = icmp eq i64 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %6
%15 = tail call i32 @myWarn_Loc(i32 3, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), i32 743, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %38
16: ; preds = %6
%17 = tail call i32 @strcpy(i8* %12, i8* %0)
br label %35
18: ; preds = %3
%19 = ptrtoint i8* %4 to i64
%20 = ptrtoint i8* %0 to i64
%21 = sub i64 %19, %20
%22 = tail call i32 @strlen(i8* %1)
%23 = trunc i64 %21 to i32
%24 = add i32 %23, 1
%25 = add i32 %24, %22
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %2
%28 = icmp eq i64 %26, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = tail call i32 @myWarn_Loc(i32 3, i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str, i64 0, i64 0), i32 751, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %38
31: ; preds = %18
%32 = tail call i32 @strncpy(i8* %27, i8* %0, i32 %23)
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 %21
store i8 0, i8* %34
br label %35
35: ; preds = %31, %16
%36 = load i8*, i8** %2
%37 = tail call i32 @strcat(i8* %36, i8* %1)
br label %38
38: ; preds = %35, %29, %14
%39 = phi i32 [ -1, %14 ], [ 0, %35 ], [ -1, %29 ]
ret i32 %39
}