#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*/ fullname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gitstrlcpy(char *, char const *, int);
int parse_desktop_file(int /*<<< orphan*/ *);
int parse_directory_file(int /*<<< orphan*/ *, char *);
size_t strlen(char const *);
int /*<<< orphan*/ warn(char *, char *);
void process_file(char *filename, const char *path, int isdir) {
  FILE *fp;
  char fullname[4096];
  int ret;
  size_t len;
  len = strlen(path);
  gitstrlcpy(fullname, path, sizeof(fullname));
  gitstrlcpy(fullname + len, filename, sizeof(fullname) - len);
  fp = fopen(fullname, "r");
  if (!fp) {
    warn("could not open file %s", filename);
    return;
  }
  if (isdir)
    ret = parse_directory_file(fp, filename);
  else
    ret = parse_desktop_file(fp);
  fclose(fp);
  if (ret < 0)
    warn("file '%s' is not utf-8 compatible", filename);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <gitstrlcpy@plt>
lea    -0x1020(%rbp),%rdi
add    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x1000,%eax
sub    -0x1030(%rbp),%rax
mov    %eax,%edx
call   1090 <gitstrlcpy@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1207 <process_file+0x97>
mov    -0x8(%rbp),%rsi
lea    0xe05(%rip),%rdi
call   1030 <warn@plt>
jmp    125e <process_file+0xee>
cmpl   $0x0,-0x14(%rbp)
je     1229 <process_file+0xb9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <parse_directory_file@plt>
mov    %eax,-0x1024(%rbp)
jmp    1238 <process_file+0xc8>
mov    -0x20(%rbp),%rdi
call   1080 <parse_desktop_file@plt>
mov    %eax,-0x1024(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpl   $0x0,-0x1024(%rbp)
jge    125e <process_file+0xee>
mov    -0x8(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1030 <warn@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %rax,%r13
mov    %rsp,%r12
mov    $0x1000,%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1090 <gitstrlcpy@plt>
lea    (%rsp,%r13,1),%rdi
sub    %r13d,%ebp
mov    %r15,%rsi
mov    %ebp,%edx
call   1090 <gitstrlcpy@plt>
lea    0xe3b(%rip),%rsi
mov    %r12,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e7 <process_file+0x77>
mov    %rax,%rbp
mov    %rax,%rdi
test   %r14d,%r14d
je     11f0 <process_file+0x80>
mov    %r15,%rsi
call   1060 <parse_directory_file@plt>
jmp    11f5 <process_file+0x85>
lea    0xe14(%rip),%rdi
jmp    120a <process_file+0x9a>
call   1080 <parse_desktop_file@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %ebx,%ebx
jns    1212 <process_file+0xa2>
lea    0xe0f(%rip),%rdi
mov    %r15,%rsi
call   1030 <warn@plt>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
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"
@.str.2 = [34 x i8] c"file '%s' is not utf-8 compatible\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 [4096 x i8]
%9 = alloca i32
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = call i64 @strlen(i8* %11)
store i64 %12, i64* %10
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = call i32 @gitstrlcpy(i8* %13, i8* %14, i32 4096)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%17 = load i64, i64* %10
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8*, i8** %4
%20 = load i64, i64* %10
%21 = sub i64 4096, %20
%22 = trunc i64 %21 to i32
%23 = call i32 @gitstrlcpy(i8* %18, i8* %19, i32 %22)
%24 = getelementptr inbounds [4096 x i8], [4096 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 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %49
31: ; preds = %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)
store i32 %37, i32* %9
br label %41
38: ; preds = %31
%39 = load i32*, i32** %7
%40 = call i32 @parse_desktop_file(i32* %39)
store i32 %40, i32* %9
br label %41
41: ; preds = %38, %34
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %9
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %4
%48 = call i32 @warn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %47)
br label %49
49: ; preds = %28, %46, %41
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [23 x i8] c"could not open file %s\00"
@.str.2 = [34 x i8] c"file '%s' is not utf-8 compatible\00"
define void @process_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = call i32 @gitstrlcpy(i8* %5, i8* %1, i32 4096)
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %6
%9 = trunc i64 %6 to i32
%10 = sub i32 4096, %9
%11 = call i32 @gitstrlcpy(i8* %8, i8* %0, i32 %10)
%12 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %24, label %14
14: ; preds = %3
%15 = icmp eq i32 %2, 0
br i1 %15, label %18, label %16
16: ; preds = %14
%17 = call i32 @parse_directory_file(i32* %12, i8* %0)
br label %20
18: ; preds = %14
%19 = call i32 @parse_desktop_file(i32* %12)
br label %20
20: ; preds = %18, %16
%21 = phi i32 [ %17, %16 ], [ %19, %18 ]
%22 = call i32 @fclose(i32* %12)
%23 = icmp slt i32 %21, 0
br i1 %23, label %24, label %27
24: ; preds = %20, %3
%25 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), %20 ]
%26 = call i32 @warn(i8* %25, i8* %0)
br label %27
27: ; preds = %24, %20
ret void
}