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

/* Variables and functions */
scalar_t__ exec_get(char *, int, char *, char const **);
char *strdup(char *);
char *get_file_mime_type(const char *filename) {
  char buffer[64] = {0};
  const char *args[] = {"xdg-mime", "query", "filetype", filename, 0};
  if (exec_get(buffer, 63, "xdg-mime", args) < 0)
    return 0;
  return strdup(buffer);
}


x86 assembly (clang, -O0):
<get_file_mime_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    0xeaa(%rip),%rax
mov    %rax,-0x80(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x50(%rbp),%rdi
lea    -0x80(%rbp),%rcx
mov    $0x3f,%esi
lea    0xe6c(%rip),%rdx
call   1030 <exec_get@plt>
cmp    $0x0,%rax
jge    11b0 <get_file_mime_type+0x80>
movq   $0x0,-0x8(%rbp)
jmp    11bd <get_file_mime_type+0x8d>
lea    -0x50(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_mime_type>:
sub    $0x78,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
lea    0xebe(%rip),%rdx
mov    %rdx,(%rsp)
lea    0xebc(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xeb6(%rip),%rax
mov    %rax,0x10(%rsp)
mov    %rdi,0x18(%rsp)
movq   $0x0,0x20(%rsp)
lea    0x30(%rsp),%rdi
mov    %rsp,%rcx
mov    $0x3f,%esi
call   1030 <exec_get@plt>
test   %rax,%rax
js     1192 <get_file_mime_type+0x72>
lea    0x30(%rsp),%rdi
call   1040 <strdup@plt>
add    $0x78,%rsp
ret
xor    %eax,%eax
add    $0x78,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"xdg-mime\00"
@.str.1 = [6 x i8] c"query\00"
@.str.2 = [9 x i8] c"filetype\00"
define i8* @get_file_mime_type(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [64 x i8]
%5 = alloca [5 x i8*]
store i8* %0, i8** %3
%6 = bitcast [64 x i8]* %4 to i8*
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds i8*, i8** %7, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds i8*, i8** %8, i64 1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %3
store i8* %11, i8** %10
%12 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* null, i8** %12
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%14 = getelementptr inbounds [5 x i8*], [5 x i8*]* %5, i64 0, i64 0
%15 = call i64 @exec_get(i8* %13, i32 63, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %1
store i8* null, i8** %2
br label %21
18: ; preds = %1
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%20 = call i8* @strdup(i8* %19)
store i8* %20, i8** %2
br label %21
21: ; preds = %18, %17
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"xdg-mime\00"
@.str.1 = [6 x i8] c"query\00"
@.str.2 = [9 x i8] c"filetype\00"
define noalias i8* @get_file_mime_type(i8* %0) {
%2 = alloca [64 x i8]
%3 = alloca [5 x i8*]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = bitcast [5 x i8*]* %3 to i8*
%6 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
store i8* %0, i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 4
store i8* null, i8** %10
%11 = call i64 @exec_get(i8* %4, i32 63, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %6)
%12 = icmp slt i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %1
%14 = call i8* @strdup(i8* %4)
br label %15
15: ; preds = %1, %13
%16 = phi i8* [ %14, %13 ], [ null, %1 ]
ret i8* %16
}