#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*/ die(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ parse_desktop_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ parse_directory_file(int /*<<< orphan*/ *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void process_file(char *filename, const char *path, int isdir) {
  FILE *fp;
  char fullname[8192];
  strncpy(fullname, path, strlen(path));
  strncpy(fullname + strlen(path), filename, strlen(filename) + 1);
  fp = fopen(fullname, "r");
  if (!fp)
    die("could not open file %s", filename);
  if (isdir)
    parse_directory_file(fp, filename);
  else
    parse_desktop_file(fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2048(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x2040(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2048(%rbp),%rdi
mov    -0x2040(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
lea    -0x2020(%rbp),%rax
mov    %rax,-0x2038(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x2038(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x2030(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x2028(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2030(%rbp),%rdi
mov    -0x2028(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <strncpy@plt>
lea    -0x2020(%rbp),%rdi
lea    0xddc(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1248 <process_file+0xd8>
mov    -0x8(%rbp),%rsi
lea    0xdbf(%rip),%rdi
call   1080 <die@plt>
cmpl   $0x0,-0x14(%rbp)
je     1264 <process_file+0xf4>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <parse_directory_file@plt>
jmp    126d <process_file+0xfd>
mov    -0x20(%rbp),%rdi
call   1090 <parse_desktop_file@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x2050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2008,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
lea    0xe37(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11e8 <process_file+0x78>
lea    0xe22(%rip),%rdi
mov    %rbx,%rsi
call   1080 <die@plt>
mov    %rbp,%rdi
test   %r14d,%r14d
je     11fa <process_file+0x8a>
mov    %rbx,%rsi
call   1060 <parse_directory_file@plt>
jmp    11ff <process_file+0x8f>
call   1090 <parse_desktop_file@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
add    $0x2008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"could not open file %s\00"
define void @process_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [8192 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @strncpy(i8* %9, i8* %10, i32 %12)
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8*, i8** %4
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = add nsw i32 %21, 1
%23 = call i32 @strncpy(i8* %18, i8* %19, i32 %22)
%24 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %7
%26 = load i32*, i32** %7
%27 = icmp ne i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %3
%29 = load i8*, i8** %4
%30 = call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %3
%32 = load i32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32*, i32** %7
%36 = load i8*, i8** %4
%37 = call i32 @parse_directory_file(i32* %35, i8* %36)
br label %41
38: ; preds = %31
%39 = load i32*, i32** %7
%40 = call i32 @parse_desktop_file(i32* %39)
br label %41
41: ; preds = %38, %34
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"could not open file %s\00"
define void @process_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca [8192 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %1)
%7 = call i32 @strncpy(i8* %5, i8* %1, i32 %6)
%8 = call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 %9
%11 = call i32 @strlen(i8* %0)
%12 = add nsw i32 %11, 1
%13 = call i32 @strncpy(i8* %10, i8* %0, i32 %12)
%14 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %3
%17 = call i32 @die(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %16, %3
%19 = icmp eq i32 %2, 0
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = call i32 @parse_directory_file(i32* %14, i8* %0)
br label %24
22: ; preds = %18
%23 = call i32 @parse_desktop_file(i32* %14)
br label %24
24: ; preds = %22, %20
%25 = call i32 @fclose(i32* %14)
ret void
}