#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__ configdefaultdir(char *, int, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int strlen(char *);
int configdefaultfilelocation(char *path, int pathsize, char *filename,
                              char *packagename) {
  char dirname[40];
  if (configdefaultdir(dirname, 40, packagename)) {
    return 1;
  }
  if (strlen(dirname) + strlen(filename) + 2 > pathsize) {
    printf("Config file name is too long - overflow!\n");
    return 1;
  }
  sprintf(path, "%s/%s", dirname, filename);
  return 0;
}


x86 assembly (clang, -O0):
<configdefaultfilelocation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x28,%esi
call   1060 <configdefaultdir@plt>
cmp    $0x0,%rax
je     117f <configdefaultfilelocation+0x3f>
movl   $0x1,-0x4(%rbp)
jmp    11de <configdefaultfilelocation+0x9e>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cmp    -0x14(%rbp),%eax
jle    11bf <configdefaultfilelocation+0x7f>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11de <configdefaultfilelocation+0x9e>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe58(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<configdefaultfilelocation>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r15
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
mov    $0x28,%esi
mov    %rcx,%rdx
call   1060 <configdefaultdir@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11b0 <configdefaultfilelocation+0x70>
mov    %rsp,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
add    %r12d,%eax
add    $0x2,%eax
cmp    %ebx,%eax
jle    1199 <configdefaultfilelocation+0x59>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
jmp    11b0 <configdefaultfilelocation+0x70>
lea    0xe60(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
mov    %r15,%rcx
call   1050 <sprintf@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"Config file name is too long - overflow!\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @configdefaultfilelocation(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [40 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%12 = load i8*, i8** %9
%13 = call i64 @configdefaultdir(i8* %11, i32 40, i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %32
16: ; preds = %4
%17 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %8
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 2
%23 = load i32, i32* %7
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %32
27: ; preds = %16
%28 = load i8*, i8** %6
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %10, i64 0, i64 0
%30 = load i8*, i8** %8
%31 = call i32 @sprintf(i8* %28, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
store i32 0, i32* %5
br label %32
32: ; preds = %27, %25, %15
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"%s/%s\00"
@str = [41 x i8] c"Config file name is too long - overflow!\00"
define i32 @configdefaultfilelocation(i8* nocapture writeonly %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [40 x i8]
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%7 = call i64 @configdefaultdir(i8* %6, i32 40, i8* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %4
%10 = call i32 @strlen(i8* %6)
%11 = call i32 @strlen(i8* %2)
%12 = add i32 %10, 2
%13 = add i32 %12, %11
%14 = icmp sgt i32 %13, %1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
br label %19
17: ; preds = %9
%18 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6, i8* %2)
br label %19
19: ; preds = %4, %17, %15
%20 = phi i32 [ 1, %15 ], [ 0, %17 ], [ 1, %4 ]
ret i32 %20
}