#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*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void renameFile(char *fileName) {
  int size = strlen(fileName);
  int t = size--;
  while (fileName[t--] != '.') {
    fileName[t--] = '\0';
  }
  strcat(fileName, "wi");
  printf("File name is %s\n", fileName);
}


x86 assembly (clang, -O0):
<renameFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1190 <renameFile+0x60>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,-0x10(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1156 <renameFile+0x26>
mov    -0x8(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<renameFile>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
cmpb   $0x2e,(%rbx,%rax,1)
je     115d <renameFile+0x2d>
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax,%rax,1)
movb   $0x0,(%rax)
cmpb   $0x2e,-0x1(%rax)
lea    -0x2(%rax),%rax
jne    1150 <renameFile+0x20>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0xe90(%rip),%rdi
mov    %rbx,%rsi
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wi\00"
@.str.1 = [17 x i8] c"File name is %s\0A\00"
define void @renameFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = add nsw i32 %7, -1
store i32 %8, i32* %3
store i32 %7, i32* %4
br label %9
9: ; preds = %18, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 46
br i1 %17, label %18, label %24
18: ; preds = %9
%19 = load i8*, i8** %2
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
%22 = sext i32 %20 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %23
br label %9
24: ; preds = %9
%25 = load i8*, i8** %2
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = load i8*, i8** %2
%28 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %27)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wi\00"
@.str.1 = [17 x i8] c"File name is %s\0A\00"
define void @renameFile(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 46
br i1 %6, label %15, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %10, %7 ], [ %3, %1 ]
%9 = add nsw i64 %8, -1
%10 = add i64 %8, -2
%11 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 0, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 46
br i1 %14, label %15, label %7
15: ; preds = %7, %1
%16 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0)
ret void
}