#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);
  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)
mov    -0x28(%rbp),%rdi
lea    0xe6b(%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     1237 <test_if_download_temp_file+0xc7>
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    1232 <test_if_download_temp_file+0xc2>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <test_if_download_temp_file+0xd7>
jmp    1237 <test_if_download_temp_file+0xc7>
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>
mov    %rax,%rbx
lea    0xe6f(%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     11f9 <test_if_download_temp_file+0x89>
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    11f9 <test_if_download_temp_file+0x89>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
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 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 9)
%12 = load i8*, i8** %3
store i8* %12, i8** %6
%13 = load i8*, i8** %3
%14 = load i8*, i8** %5
%15 = call i64 @strstr(i8* %13, i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %1
%18 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%19 = load i8*, i8** %6
%20 = load i8*, i8** %3
%21 = call i32 @strlen(i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = sub nsw i32 %21, %23
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %19, i64 %25
%27 = call i32 @strcpy(i8* %18, i8* %26)
%28 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%29 = load i8*, i8** %5
%30 = call i32 @strcmp(i8* %28, i8* %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %17
%33 = load i8*, i8** %5
%34 = call i32 @free(i8* %33)
store i32 1, i32* %2
br label %39
35: ; preds = %17
br label %36
36: ; preds = %35, %1
%37 = load i8*, i8** %5
%38 = call i32 @free(i8* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %32
%40 = load i32, i32* %2
ret i32 %40
}

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 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @memset(i8* %3, i32 0, i32 9)
%7 = call i64 @strstr(i8* %0, i8* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %1
%10 = call i32 @strlen(i8* %0)
%11 = call i32 @strlen(i8* %4)
%12 = sub nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = call i32 @strcpy(i8* %3, i8* %14)
%16 = call i32 @strcmp(i8* %3, i8* dereferenceable(1) %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %9, %1
br label %19
19: ; preds = %9, %18
%20 = phi i32 [ 0, %18 ], [ 1, %9 ]
%21 = call i32 @free(i8* %4)
ret i32 %20
}