#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 strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
void newname(char *nname, char *oname, char *suff, int maxn) {
  strncpy(nname, oname, maxn);
  nname[maxn - 1] = '\0';
  strncat(nname, ".", maxn - strlen(nname) - 1);
  strncat(nname, suff, maxn - strlen(nname) - 1);
}


x86 assembly (clang, -O0):
<newname>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rdi
sub    %eax,%edx
sub    $0x1,%edx
lea    0xe6e(%rip),%rsi
call   1050 <strncat@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    %eax,%edx
sub    $0x1,%edx
call   1050 <strncat@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newname>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %ecx,%edx
call   1030 <strncpy@plt>
movslq %ebp,%r15
movb   $0x0,-0x1(%r15,%rbx,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
not    %eax
lea    (%rax,%r15,1),%edx
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strncat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
not    %eax
add    %eax,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strncat@plt>

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @newname(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %5
%10 = load i8*, i8** %6
%11 = load i32, i32* %8
%12 = call i32 @strncpy(i8* %9, i8* %10, i32 %11)
%13 = load i8*, i8** %5
%14 = load i32, i32* %8
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = load i8*, i8** %5
%21 = call i32 @strlen(i8* %20)
%22 = sub nsw i32 %19, %21
%23 = sub nsw i32 %22, 1
%24 = call i32 @strncat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i8*, i8** %5
%26 = load i8*, i8** %7
%27 = load i32, i32* %8
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %27, %29
%31 = sub nsw i32 %30, 1
%32 = call i32 @strncat(i8* %25, i8* %26, i32 %31)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @newname(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %3)
%6 = add nsw i32 %3, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %8
%9 = tail call i32 @strlen(i8* %0)
%10 = xor i32 %9, -1
%11 = add i32 %10, %3
%12 = tail call i32 @strncat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = tail call i32 @strlen(i8* %0)
%14 = xor i32 %13, -1
%15 = add i32 %14, %3
%16 = tail call i32 @strncat(i8* %0, i8* %2, i32 %15)
ret void
}