#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*/ tmp;

/* Variables and functions */
char *read_file(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const,
                            char const *);
char *terminfo_try_path(const char *path, const char *term) {
  char tmp[4096];
  snprintf(tmp, sizeof(tmp), "%s/%c/%s", path, term[0], term);
  tmp[sizeof(tmp) - 1] = '\0';
  char *data = read_file(tmp);
  if (data) {
    return data;
  }
  snprintf(tmp, sizeof(tmp), "%s/%x/%s", path, term[0], term);
  tmp[sizeof(tmp) - 1] = '\0';
  return read_file(tmp);
}


x86 assembly (clang, -O0):
<terminfo_try_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%r9
mov    $0x1000,%esi
lea    0xeac(%rip),%rdx
movsbl %al,%r8d
call   1030 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <read_file@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
je     1192 <terminfo_try_path+0x72>
mov    -0x1028(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <terminfo_try_path+0xb0>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    -0x18(%rbp),%r9
mov    $0x1000,%esi
lea    0xe56(%rip),%rdx
movsbl %al,%r8d
call   1030 <snprintf@plt>
movb   $0x0,-0x21(%rbp)
lea    -0x1020(%rbp),%rdi
call   1040 <read_file@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<terminfo_try_path>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movsbl (%rsi),%r8d
lea    0xec3(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbx,%r9
call   1030 <snprintf@plt>
movb   $0x0,0xfff(%rsp)
mov    %r15,%rdi
call   1040 <read_file@plt>
test   %rax,%rax
jne    1199 <terminfo_try_path+0x79>
movsbl (%rbx),%r8d
lea    0xe96(%rip),%rdx
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%rcx
mov    %rbx,%r9
call   1030 <snprintf@plt>
movb   $0x0,0xfff(%rsp)
mov    %r15,%rdi
call   1040 <read_file@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%s/%c/%s\00"
@.str.1 = [9 x i8] c"%s/%x/%s\00"
define i8* @terminfo_try_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = load i8*, i8** %5
%14 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %9, i8 signext %12, i8* %13)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 4095
store i8 0, i8* %15
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = call i8* @read_file(i8* %16)
store i8* %17, i8** %7
%18 = load i8*, i8** %7
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = load i8*, i8** %7
store i8* %21, i8** %3
br label %33
22: ; preds = %2
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = load i8*, i8** %5
%29 = call i32 @snprintf(i8* %23, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8 signext %27, i8* %28)
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 4095
store i8 0, i8* %30
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%32 = call i8* @read_file(i8* %31)
store i8* %32, i8** %3
br label %33
33: ; preds = %22, %20
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s/%c/%s\00"
@.str.1 = [9 x i8] c"%s/%x/%s\00"
define i8* @terminfo_try_path(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %1
%6 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0, i8 signext %5, i8* %1)
%7 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 4095
store i8 0, i8* %7
%8 = call i8* @read_file(i8* %4)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i8, i8* %1
%12 = call i32 @snprintf(i8* %4, i32 4096, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8 signext %11, i8* %1)
store i8 0, i8* %7
%13 = call i8* @read_file(i8* %4)
br label %14
14: ; preds = %2, %10
%15 = phi i8* [ %13, %10 ], [ %8, %2 ]
ret i8* %15
}