#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 - 1);
  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
sub    $0x1,%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    0xe6b(%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   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%rbx
movslq %ecx,%r15
lea    -0x1(%r15),%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%rbx,%r15,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
not    %eax
lea    (%rax,%r15,1),%edx
lea    0xe9e(%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
pop    %rbx
pop    %r14
pop    %r15
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 = sub nsw i32 %11, 1
%13 = call i32 @strncpy(i8* %9, i8* %10, i32 %12)
%14 = load i8*, i8** %5
%15 = load i32, i32* %8
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 0, i8* %18
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %20, %22
%24 = sub nsw i32 %23, 1
%25 = call i32 @strncat(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8*, i8** %5
%27 = load i8*, i8** %7
%28 = load i32, i32* %8
%29 = load i8*, i8** %5
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %28, %30
%32 = sub nsw i32 %31, 1
%33 = call i32 @strncat(i8* %26, i8* %27, i32 %32)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @newname(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = add nsw i32 %3, -1
%6 = tail call i32 @strncpy(i8* %0, i8* %1, i32 %5)
%7 = sext i32 %5 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
}