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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
char *long_name(char *path, char *shortname) {
  static char line[4096];
  char filename[4096], temp[4096], *c;
  FILE *file;
  sprintf(line, "%s ", shortname);
  sprintf(filename, "%s/vendor_name", path);
  file = fopen(filename, "r");
  if (file) {
    if (fgets(temp, 4096, file))
      strcat(line, temp);
    fclose(file);
  }
  sprintf(filename, "%s/chip_name", path);
  file = fopen(filename, "r");
  if (file) {
    if (fgets(temp, 4096, file))
      strcat(line, temp);
    fclose(file);
  }
  while ((c = strchr(line, '\n')))
    *c = ' ';
  return line;
}


x86 assembly (clang, -O0):
<long_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
lea    0x2ee2(%rip),%rdi
lea    0xe7b(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe68(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x2020(%rbp)
cmpq   $0x0,-0x2020(%rbp)
je     120a <long_name+0xaa>
lea    -0x2010(%rbp),%rdi
mov    -0x2020(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fe <long_name+0x9e>
lea    -0x2010(%rbp),%rsi
lea    0x2e67(%rip),%rdi
call   1070 <strcat@plt>
mov    -0x2020(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xdf9(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x2020(%rbp)
cmpq   $0x0,-0x2020(%rbp)
je     128a <long_name+0x12a>
lea    -0x2010(%rbp),%rdi
mov    -0x2020(%rbp),%rdx
mov    $0x1000,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     127e <long_name+0x11e>
lea    -0x2010(%rbp),%rsi
lea    0x2de7(%rip),%rdi
call   1070 <strcat@plt>
mov    -0x2020(%rbp),%rdi
call   1030 <fclose@plt>
jmp    128f <long_name+0x12f>
lea    0x2dca(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x2018(%rbp)
cmp    $0x0,%rax
je     12c0 <long_name+0x160>
mov    -0x2018(%rbp),%rax
movb   $0x20,(%rax)
jmp    128f <long_name+0x12f>
lea    0x2d99(%rip),%rax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<long_name>:
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %rsi,%rdx
mov    %rdi,%r14
lea    0x2ee9(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe7a(%rip),%rsi
lea    0x1000(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e0 <long_name+0x80>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11d8 <long_name+0x78>
lea    0x2e90(%rip),%rdi
mov    %rsp,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe2e(%rip),%rsi
lea    0x1000(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1080 <sprintf@plt>
lea    0xe12(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     123d <long_name+0xdd>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1000,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1235 <long_name+0xd5>
lea    0x2e33(%rip),%rdi
mov    %rsp,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0x2e1c(%rip),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1275 <long_name+0x115>
lea    0x2e06(%rip),%rbx
nopw   0x0(%rax,%rax,1)
movb   $0x20,(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1260 <long_name+0x100>
lea    0x2de4(%rip),%rax
add    $0x2008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@long_name.line = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"%s \00"
@.str.1 = [15 x i8] c"%s/vendor_name\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"%s/chip_name\00"
define i8* @long_name(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i32 @sprintf(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%12 = load i8*, i8** %3
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %29
18: ; preds = %2
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%20 = load i32*, i32** %8
%21 = call i64 @fgets(i8* %19, i32 4096, i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %18
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
br label %29
29: ; preds = %26, %2
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%31 = load i8*, i8** %3
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %34, i32** %8
%35 = load i32*, i32** %8
%36 = icmp ne i32* %35, null
br i1 %36, label %37, label %48
37: ; preds = %29
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%39 = load i32*, i32** %8
%40 = call i64 @fgets(i8* %38, i32 4096, i32* %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %42, %37
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %29
br label %49
49: ; preds = %52, %48
%50 = call i8* @strchr(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8 signext 10)
store i8* %50, i8** %7
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = load i8*, i8** %7
store i8 32, i8* %53
br label %49
54: ; preds = %49
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0)
}

LLVM IR (-O2):
@long_name.line = internal global [4096 x i8] zeroinitializer
@.str = [4 x i8] c"%s \00"
@.str.1 = [15 x i8] c"%s/vendor_name\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [13 x i8] c"%s/chip_name\00"
define i8* @long_name(i8* %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %18, label %11
11: ; preds = %2
%12 = call i64 @fgets(i8* %6, i32 4096, i32* %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* %6)
br label %16
16: ; preds = %14, %11
%17 = call i32 @fclose(i32* %9)
br label %18
18: ; preds = %16, %2
%19 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%20 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %29, label %22
22: ; preds = %18
%23 = call i64 @fgets(i8* %6, i32 4096, i32* %20)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = call i32 @strcat(i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8* %6)
br label %27
27: ; preds = %25, %22
%28 = call i32 @fclose(i32* %20)
br label %29
29: ; preds = %27, %18
%30 = call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8 signext 10)
%31 = icmp eq i8* %30, null
br i1 %31, label %36, label %32
32: ; preds = %29, %32
%33 = phi i8* [ %34, %32 ], [ %30, %29 ]
store i8 32, i8* %33
%34 = call i8* @strchr(i8* dereferenceable(1) getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0), i8 signext 10)
%35 = icmp eq i8* %34, null
br i1 %35, label %36, label %32
36: ; preds = %32, %29
ret i8* getelementptr inbounds ([4096 x i8], [4096 x i8]* @long_name.line, i64 0, i64 0)
}