#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 add_app(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gitstrcasestr(char *, char *);
int /*<<< orphan*/ gitstrlcpy(char *, char const *, int);
scalar_t__ is_duplicate_desktop_file(char *);
size_t strlen(char const *);
int /*<<< orphan*/ warn(char *, char *);
void process_file(char *filename, const char *path) {
  FILE *fp;
  char fullname[4096];
  int ret = 0;
  size_t len;
  if (!gitstrcasestr(filename, ".desktop"))
    return;
  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 (is_duplicate_desktop_file(filename))
    goto out;
  ret = add_app(fp, filename);
  if (ret < 0)
    warn("file '%s' is not utf-8 compatible", filename);
out:
  fclose(fp);
}


x86 assembly (clang, -O0):
<process_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1024(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1030 <gitstrcasestr@plt>
cmp    $0x0,%eax
jne    11bb <process_file+0x3b>
jmp    1292 <process_file+0x112>
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x1030(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   10a0 <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   10a0 <gitstrlcpy@plt>
lea    -0x1020(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    123c <process_file+0xbc>
mov    -0x8(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1040 <warn@plt>
jmp    1292 <process_file+0x112>
mov    -0x8(%rbp),%rdi
call   1050 <is_duplicate_desktop_file@plt>
cmp    $0x0,%rax
je     1254 <process_file+0xd4>
jmp    1289 <process_file+0x109>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1080 <add_app@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jge    1284 <process_file+0x104>
mov    -0x8(%rbp),%rsi
lea    0xda3(%rip),%rdi
call   1040 <warn@plt>
jmp    1289 <process_file+0x109>
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe64(%rip),%rsi
call   1030 <gitstrcasestr@plt>
test   %eax,%eax
je     1237 <process_file+0xb7>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
mov    %rsp,%r12
mov    $0x1000,%ebp
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x1000,%edx
call   10a0 <gitstrlcpy@plt>
lea    (%rsp,%rbx,1),%rdi
sub    %ebx,%ebp
mov    %r15,%rsi
mov    %ebp,%edx
call   10a0 <gitstrlcpy@plt>
lea    0xe26(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1228 <process_file+0xa8>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <is_duplicate_desktop_file@plt>
test   %rax,%rax
jne    121e <process_file+0x9e>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <add_app@plt>
test   %eax,%eax
jns    121e <process_file+0x9e>
lea    0xe0c(%rip),%rdi
mov    %r15,%rsi
call   1040 <warn@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
jmp    1237 <process_file+0xb7>
lea    0xddc(%rip),%rdi
mov    %r15,%rsi
call   1040 <warn@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c".desktop\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"could not open file %s\00"
@.str.3 = [34 x i8] c"file '%s' is not utf-8 compatible\00"
define void @process_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %7
%9 = load i8*, i8** %3
%10 = call i32 @gitstrcasestr(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
br label %52
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i64 @strlen(i8* %14)
store i64 %15, i64* %8
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %4
%18 = call i32 @gitstrlcpy(i8* %16, i8* %17, i32 4096)
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%20 = load i64, i64* %8
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8*, i8** %3
%23 = load i64, i64* %8
%24 = sub i64 4096, %23
%25 = trunc i64 %24 to i32
%26 = call i32 @gitstrlcpy(i8* %21, i8* %22, i32 %25)
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %5
%29 = load i32*, i32** %5
%30 = icmp ne i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %13
%32 = load i8*, i8** %3
%33 = call i32 @warn(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %52
34: ; preds = %13
%35 = load i8*, i8** %3
%36 = call i64 @is_duplicate_desktop_file(i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %49
39: ; preds = %34
%40 = load i32*, i32** %5
%41 = load i8*, i8** %3
%42 = call i32 @add_app(i32* %40, i8* %41)
store i32 %42, i32* %7
%43 = load i32, i32* %7
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %39
%46 = load i8*, i8** %3
%47 = call i32 @warn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %45, %39
br label %49
49: ; preds = %48, %38
%50 = load i32*, i32** %5
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %49, %31, %12
ret void
}

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