#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 */
int EXIT_SUCCESS;
int L_tmpnam;
int /*<<< orphan*/ error_check_arg(int, char *, char const *);
char *file_read_text(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ file_temporary_name(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ remove(char *);
int /*<<< orphan*/ sprintf(char *, char const *, char *);
int system(char *);
char const *guess_mime_type_2(char const name_[]) {
  char temp_name[L_tmpnam];
  file_temporary_name(temp_name);
  char command[256] = "file -bIL %s > %s";
  sprintf(command, name_, temp_name);
  int status = system(command);
  error_check_arg(status != EXIT_SUCCESS,
                  "failed retrieval of mime type on \"%s\"", name_);
  char *mime_type = file_read_text(temp_name, NULL);
  if (remove(temp_name) != 0)
    perror("failed to delete");
  return mime_type;
}


x86 assembly (clang, -O0):
<guess_mime_type_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x138(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
call   1060 <file_temporary_name@plt>
lea    -0x120(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x100,%edx
call   1070 <memcpy@plt>
mov    -0x138(%rbp),%rdx
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10a0 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <system@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
mov    -0x8(%rbp),%rdx
lea    0xeda(%rip),%rsi
call   1080 <error_check_arg@plt>
mov    -0x138(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <file_read_text@plt>
mov    -0x138(%rbp),%rdi
mov    %rax,-0x130(%rbp)
call   1030 <remove@plt>
cmp    $0x0,%rax
je     1264 <guess_mime_type_2+0xe4>
lea    0xec7(%rip),%rdi
call   1090 <perror@plt>
mov    -0x130(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_mime_type_2>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1060 <file_temporary_name@plt>
lea    0xe44(%rip),%rsi
lea    -0x120(%rbp),%r15
mov    $0x100,%edx
mov    %r15,%rdi
call   1070 <memcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
mov    %r15,%rdi
call   1050 <system@plt>
mov    0x2deb(%rip),%rcx
xor    %edi,%edi
cmp    (%rcx),%eax
setne  %dil
lea    0xf04(%rip),%rsi
mov    %r14,%rdx
call   1080 <error_check_arg@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <file_read_text@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <remove@plt>
test   %rax,%rax
jne    122c <guess_mime_type_2+0xac>
mov    %r14,%rax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xef3(%rip),%rdi
call   1090 <perror@plt>
jmp    121e <guess_mime_type_2+0x9e>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@__const.guess_mime_type_2.command = [256 x i8] c"file -bIL %s > %s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_SUCCESS = global i32 0
@.str = [38 x i8] c"failed retrieval of mime type on \22%s\22\00"
@.str.1 = [17 x i8] c"failed to delete\00"
define i8* @guess_mime_type_2(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca [256 x i8]
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i32, i32* @L_tmpnam
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = call i32 @file_temporary_name(i8* %11)
%13 = bitcast [256 x i8]* %5 to i8*
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = call i32 @sprintf(i8* %14, i8* %15, i8* %11)
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%18 = call i32 @system(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* @EXIT_SUCCESS
%21 = icmp ne i32 %19, %20
%22 = zext i1 %21 to i32
%23 = load i8*, i8** %2
%24 = call i32 @error_check_arg(i32 %22, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i8* @file_read_text(i8* %11, i32* null)
store i8* %25, i8** %7
%26 = call i64 @remove(i8* %11)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %1
%29 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %1
%31 = load i8*, i8** %7
%32 = load i8*, i8** %3
ret i8* %31
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@__const.guess_mime_type_2.command = [256 x i8] c"file -bIL %s > %s\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_SUCCESS = global i32 0
@.str = [38 x i8] c"failed retrieval of mime type on \22%s\22\00"
@.str.1 = [17 x i8] c"failed to delete\00"
define i8* @guess_mime_type_2(i8* %0) {
%2 = alloca [256 x i8]
%3 = load i32, i32* @L_tmpnam
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @file_temporary_name(i8* %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) %0, i8* %5)
%9 = call i32 @system(i8* %7)
%10 = load i32, i32* @EXIT_SUCCESS
%11 = icmp ne i32 %9, %10
%12 = zext i1 %11 to i32
%13 = call i32 @error_check_arg(i32 %12, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* %0)
%14 = call i8* @file_read_text(i8* %5, i32* null)
%15 = call i64 @remove(i8* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %1
%18 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %1
ret i8* %14
}