#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_suffix;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *my_malloc(int);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
scalar_t__ strstr(char *, char *);
int test_if_download_temp_file(char *filename) {
  char file_suffix[9];
  char *temp_suffix = my_malloc(9);
  if (temp_suffix == NULL) {
    return -1;
  }
  strcpy(temp_suffix, ".asus.td");
  memset(file_suffix, 0, sizeof(file_suffix));
  char *p = filename;
  if (strstr(filename, temp_suffix)) {
    strcpy(file_suffix, p + (strlen(filename) - strlen(temp_suffix)));
    if (!strcmp(file_suffix, temp_suffix)) {
      free(temp_suffix);
      return 1;
    }
  }
  free(temp_suffix);
  return 0;
}


x86 assembly (clang, -O0):
<test_if_download_temp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x9,%edi
call   1040 <my_malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a1 <test_if_download_temp_file+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    125e <test_if_download_temp_file+0xee>
mov    -0x28(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1050 <strcpy@plt>
lea    -0x19(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     124e <test_if_download_temp_file+0xde>
lea    -0x19(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
sub    %ecx,%eax
cltq
add    %rax,%rsi
call   1050 <strcpy@plt>
lea    -0x19(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1249 <test_if_download_temp_file+0xd9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    125e <test_if_download_temp_file+0xee>
jmp    124e <test_if_download_temp_file+0xde>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_if_download_temp_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    $0x9,%edi
call   1040 <my_malloc@plt>
test   %rax,%rax
je     1208 <test_if_download_temp_file+0x98>
mov    %rax,%rbx
lea    0xe6a(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
lea    0xf(%rsp),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
mov    $0x9,%edx
call   1070 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11fe <test_if_download_temp_file+0x8e>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
sub    %eax,%ebp
movslq %ebp,%rsi
add    %r15,%rsi
lea    0xf(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <strcpy@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    11fe <test_if_download_temp_file+0x8e>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    120e <test_if_download_temp_file+0x9e>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c".asus.td\00"
define i32 @test_if_download_temp_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [9 x i8]
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
%7 = call i8* @my_malloc(i32 9)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %43
11: ; preds = %1
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i32 0, i32 9)
%16 = load i8*, i8** %3
store i8* %16, i8** %6
%17 = load i8*, i8** %3
%18 = load i8*, i8** %5
%19 = call i64 @strstr(i8* %17, i8* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %11
%22 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @strlen(i8* %26)
%28 = sub nsw i32 %25, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %23, i64 %29
%31 = call i32 @strcpy(i8* %22, i8* %30)
%32 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = call i32 @strcmp(i8* %32, i8* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %21
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
store i32 1, i32* %2
br label %43
39: ; preds = %21
br label %40
40: ; preds = %39, %11
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
store i32 0, i32* %2
br label %43
43: ; preds = %40, %36, %10
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [9 x i8] c".asus.td\00"
define i32 @test_if_download_temp_file(i8* %0) {
%2 = alloca [9 x i8]
%3 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @my_malloc(i32 9)
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @memset(i8* %3, i32 0, i32 9)
%9 = call i64 @strstr(i8* %0, i8* %4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = call i32 @strlen(i8* %0)
%13 = call i32 @strlen(i8* %4)
%14 = sub nsw i32 %12, %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = call i32 @strcpy(i8* %3, i8* %16)
%18 = call i32 @strcmp(i8* %3, i8* %4)
%19 = icmp eq i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %11, %6
br label %21
21: ; preds = %11, %20
%22 = phi i32 [ 0, %20 ], [ 1, %11 ]
%23 = call i32 @free(i8* %4)
br label %24
24: ; preds = %21, %1
%25 = phi i32 [ -1, %1 ], [ %22, %21 ]
ret i32 %25
}