#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 */
scalar_t__ fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
scalar_t__ system(char *);
scalar_t__ tmpnam(char *);
int CWS_Get_FileType(const char *file, char *typestring, size_t tslen) {
  char cmdbuffer[300];
  char cmdout[300];
  FILE *fcmdout;
  if (file && tmpnam(cmdout)) {
    sprintf(cmdbuffer, "file %s > %s", file, cmdout);
    if (system(cmdbuffer) == 0 && (fcmdout = fopen(cmdout, "r")) &&
        fgets(typestring, tslen, fcmdout))
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<CWS_Get_FileType>:
push   %rbp
mov    %rsp,%rbp
sub    $0x290,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120f <CWS_Get_FileType+0xbf>
lea    -0x280(%rbp),%rdi
call   1070 <tmpnam@plt>
cmp    $0x0,%rax
je     120f <CWS_Get_FileType+0xbf>
lea    -0x150(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x280(%rbp),%rcx
lea    0xe5f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x150(%rbp),%rdi
call   1030 <system@plt>
cmp    $0x0,%rax
jne    120a <CWS_Get_FileType+0xba>
lea    -0x280(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x288(%rbp)
cmp    $0x0,%rax
je     120a <CWS_Get_FileType+0xba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x288(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     120a <CWS_Get_FileType+0xba>
movl   $0x0,-0x4(%rbp)
jmp    1216 <CWS_Get_FileType+0xc6>
jmp    120f <CWS_Get_FileType+0xbf>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x290,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CWS_Get_FileType>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x268,%rsp
test   %rdi,%rdi
je     11a3 <CWS_Get_FileType+0x53>
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1070 <tmpnam@plt>
test   %rax,%rax
je     11a3 <CWS_Get_FileType+0x53>
lea    0xe80(%rip),%rsi
lea    0x130(%rsp),%r12
mov    %rsp,%rcx
mov    %r12,%rdi
mov    %rbx,%rdx
call   1060 <sprintf@plt>
mov    %r12,%rdi
call   1030 <system@plt>
test   %rax,%rax
je     11b7 <CWS_Get_FileType+0x67>
mov    $0x1,%eax
add    $0x268,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe4f(%rip),%rsi
mov    %rsp,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a3 <CWS_Get_FileType+0x53>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    11a8 <CWS_Get_FileType+0x58>
jmp    11a3 <CWS_Get_FileType+0x53>

LLVM IR (-O0):
@.str = [13 x i8] c"file %s > %s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @CWS_Get_FileType(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [300 x i8]
%9 = alloca [300 x i8]
%10 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** %5
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %37
13: ; preds = %3
%14 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%15 = call i64 @tmpnam(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %13
%18 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %19, i8* %20)
%22 = getelementptr inbounds [300 x i8], [300 x i8]* %8, i64 0, i64 0
%23 = call i64 @system(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %17
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %10
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = load i64, i64* %7
%32 = load i32*, i32** %10
%33 = call i64 @fgets(i8* %30, i64 %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 0, i32* %4
br label %38
36: ; preds = %29, %25, %17
br label %37
37: ; preds = %36, %13, %3
store i32 1, i32* %4
br label %38
38: ; preds = %37, %35
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@.str = [13 x i8] c"file %s > %s\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @CWS_Get_FileType(i8* %0, i8* %1, i64 %2) {
%4 = alloca [300 x i8]
%5 = alloca [300 x i8]
%6 = getelementptr inbounds [300 x i8], [300 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %0, null
br i1 %8, label %22, label %9
9: ; preds = %3
%10 = call i64 @tmpnam(i8* %7)
%11 = icmp eq i64 %10, 0
br i1 %11, label %22, label %12
12: ; preds = %9
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7)
%14 = call i64 @system(i8* %6)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i64 @fgets(i8* %1, i64 %2, i32* %17)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %12, %16, %19, %9, %3
br label %23
23: ; preds = %19, %22
%24 = phi i32 [ 1, %22 ], [ 0, %19 ]
ret i32 %24
}