#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 */
typedef int /*<<< orphan*/ bak_extname;

/* Variables and functions */
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *osys_path_mkbak(char *buffer, size_t bufsize, const char *path) {
  static const char bak_extname[] = "."
                                    "bak";
  if (strlen(path) + sizeof(bak_extname) > bufsize)
    return NULL;
  strcpy(buffer, path);
  strcat(buffer, bak_extname);
  return buffer;
}


x86 assembly (clang, -O0):
<osys_path_mkbak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x5,%rax
cmp    -0x18(%rbp),%rax
jbe    116a <osys_path_mkbak+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    118f <osys_path_mkbak+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<osys_path_mkbak>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rdx,%rdi
call   1040 <strlen@plt>
cltq
add    $0x5,%rax
cmp    %r15,%rax
jbe    1155 <osys_path_mkbak+0x25>
xor    %ebx,%ebx
jmp    116f <osys_path_mkbak+0x3f>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@osys_path_mkbak.bak_extname = internal constant [5 x i8] c".bak\00"
define i8* @osys_path_mkbak(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%8 = load i8*, i8** %7
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = add i64 %10, 5
%12 = load i64, i64* %6
%13 = icmp ugt i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %3
store i8* null, i8** %4
br label %22
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i8*, i8** %7
%18 = call i32 @strcpy(i8* %16, i8* %17)
%19 = load i8*, i8** %5
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @osys_path_mkbak.bak_extname, i64 0, i64 0))
%21 = load i8*, i8** %5
store i8* %21, i8** %4
br label %22
22: ; preds = %15, %14
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@osys_path_mkbak.bak_extname = internal constant [5 x i8] c".bak\00"
define i8* @osys_path_mkbak(i8* %0, i64 %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %2)
%5 = sext i32 %4 to i64
%6 = add nsw i64 %5, 5
%7 = icmp ugt i64 %6, %1
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @strcpy(i8* %0, i8* %2)
%10 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @osys_path_mkbak.bak_extname, i64 0, i64 0))
br label %11
11: ; preds = %3, %8
%12 = phi i8* [ %0, %8 ], [ null, %3 ]
ret i8* %12
}