#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 */
struct dirent {
  char *d_name;
};

/* Variables and functions */
int snprintf(char *, int, char *, char const *, char *);
char *dir_entry_path(const char *dir_path, struct dirent *entry) {
  static char buf[512];
  int ret;
  ret = snprintf(buf, 512, "%s/%s", dir_path, entry->d_name);
  if (ret < 0 || ret >= 512) {
    return NULL;
  }
  return buf;
}


x86 assembly (clang, -O0):
<dir_entry_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8
lea    0x2f0e(%rip),%rdi
mov    $0x200,%esi
lea    0xec2(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     115d <dir_entry_path+0x4d>
cmpl   $0x200,-0x1c(%rbp)
jl     116a <dir_entry_path+0x5a>
movq   $0x0,-0x8(%rbp)
jmp    1175 <dir_entry_path+0x65>
lea    0x2ecf(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_entry_path>:
push   %rbx
mov    %rdi,%rcx
mov    (%rsi),%r8
lea    0x2f22(%rip),%rbx
lea    0xedb(%rip),%rdx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1030 <snprintf@plt>
xor    %ecx,%ecx
cmp    $0x200,%eax
cmovb  %rbx,%rcx
mov    %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@dir_entry_path.buf = internal global [512 x i8] zeroinitializer
@.str = [6 x i8] c"%s/%s\00"
define i8* @dir_entry_path(i8* %0, %struct.dirent* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.dirent*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.dirent* %1, %struct.dirent** %5
%7 = load i8*, i8** %4
%8 = load %struct.dirent*, %struct.dirent** %5
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @dir_entry_path.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp sge i32 %15, 512
br i1 %16, label %17, label %18
17: ; preds = %14, %2
store i8* null, i8** %3
br label %19
18: ; preds = %14
store i8* getelementptr inbounds ([512 x i8], [512 x i8]* @dir_entry_path.buf, i64 0, i64 0), i8** %3
br label %19
19: ; preds = %18, %17
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@dir_entry_path.buf = internal global [512 x i8] zeroinitializer
@.str = [6 x i8] c"%s/%s\00"
define i8* @dir_entry_path(i8* %0, %struct.dirent* nocapture %1) {
%3 = getelementptr inbounds %struct.dirent, %struct.dirent* %1, i64 0, i32 0
%4 = load i8*, i8** %3
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @dir_entry_path.buf, i64 0, i64 0), i32 512, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %4)
%6 = icmp ugt i32 %5, 511
%7 = select i1 %6, i8* null, i8* getelementptr inbounds ([512 x i8], [512 x i8]* @dir_entry_path.buf, i64 0, i64 0)
ret i8* %7
}