#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*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void troca_extensao(char **antigo, char **novo, char *extensao) {
  char *temp = NULL;
  int tamanho;
  temp = (char *)malloc((strlen(*antigo) + 2) * sizeof(char));
  tamanho = strlen(*antigo);
  strncpy(temp, *antigo, tamanho);
  temp[tamanho - 2] = '\0';
  strcat(temp, extensao);
  *novo = temp;
}


x86 assembly (clang, -O0):
<troca_extensao>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x24(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<troca_extensao>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rdi),%rdi
call   1040 <strlen@plt>
lea    0x2(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    (%r12),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    (%r12),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1030 <strncpy@plt>
movslq %ebp,%rax
movb   $0x0,-0x2(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
mov    %rbx,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @troca_extensao(i8** %0, i8** %1, i8* %2) {
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i8** %1, i8*** %5
store i8* %2, i8** %6
store i8* null, i8** %7
%9 = load i8**, i8*** %4
%10 = load i8*, i8** %9
%11 = call i32 @strlen(i8* %10)
%12 = add nsw i32 %11, 2
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %7
%18 = load i8**, i8*** %4
%19 = load i8*, i8** %18
%20 = call i32 @strlen(i8* %19)
store i32 %20, i32* %8
%21 = load i8*, i8** %7
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i32, i32* %8
%25 = call i32 @strncpy(i8* %21, i8* %23, i32 %24)
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = sub nsw i32 %27, 2
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %26, i64 %29
store i8 0, i8* %30
%31 = load i8*, i8** %7
%32 = load i8*, i8** %6
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %7
%35 = load i8**, i8*** %5
store i8* %34, i8** %35
ret void
}

LLVM IR (-O2):
define void @troca_extensao(i8** nocapture %0, i8** nocapture writeonly %1, i8* %2) {
%4 = load i8*, i8** %0
%5 = tail call i32 @strlen(i8* %4)
%6 = add nsw i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = load i8*, i8** %0
%10 = tail call i32 @strlen(i8* %9)
%11 = load i8*, i8** %0
%12 = tail call i32 @strncpy(i8* %8, i8* %11, i32 %10)
%13 = add nsw i32 %10, -2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %8, i64 %14
store i8 0, i8* %15
%16 = tail call i32 @strcat(i8* %8, i8* %2)
store i8* %8, i8** %1
ret void
}