#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char const *strstr(char const *, char *);
char *test_and_fetch(const char *fn) {
  FILE *fp;
  if (strstr(fn, "ftp://") == fn || strstr(fn, "http://") == fn) {
    return 0;
  } else {
    if ((fp = fopen(fn, "rb")) == 0)
      return 0;
    fclose(fp);
    return (char *)fn;
  }
}


x86 assembly (clang, -O0):
<test_and_fetch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
cmp    -0x10(%rbp),%rax
je     1170 <test_and_fetch+0x40>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1050 <strstr@plt>
cmp    -0x10(%rbp),%rax
jne    117d <test_and_fetch+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <test_and_fetch+0x89>
mov    -0x10(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a8 <test_and_fetch+0x78>
movq   $0x0,-0x8(%rbp)
jmp    11b9 <test_and_fetch+0x89>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_and_fetch>:
push   %rbx
mov    %rdi,%rbx
lea    0xec5(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     117f <test_and_fetch+0x4f>
lea    0xeb7(%rip),%rsi
mov    $0x7,%edx
mov    %rbx,%rdi
call   1030 <strncmp@plt>
test   %eax,%eax
je     117f <test_and_fetch+0x4f>
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     117f <test_and_fetch+0x4f>
mov    %rax,%rdi
call   1040 <fclose@plt>
jmp    1181 <test_and_fetch+0x51>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ftp://\00"
@.str.1 = [8 x i8] c"http://\00"
@.str.2 = [3 x i8] c"rb\00"
define i8* @test_and_fetch(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strstr(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = load i8*, i8** %3
%8 = icmp eq i8* %6, %7
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i8* @strstr(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%12 = load i8*, i8** %3
%13 = icmp eq i8* %11, %12
br i1 %13, label %14, label %15
14: ; preds = %9, %1
store i8* null, i8** %2
br label %24
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %4
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %20
19: ; preds = %15
store i8* null, i8** %2
br label %24
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
%23 = load i8*, i8** %3
store i8* %23, i8** %2
br label %24
24: ; preds = %20, %19, %14
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [7 x i8] c"ftp://\00"
@.str.1 = [8 x i8] c"http://\00"
@.str.2 = [3 x i8] c"rb\00"
define i8* @test_and_fetch(i8* %0) {
%2 = tail call i32 @strncmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
%3 = icmp eq i32 %2, 0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @strncmp(i8* dereferenceable(1) %0, i8* dereferenceable(8) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i64 7)
%6 = icmp eq i32 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @fclose(i32* %8)
br label %12
12: ; preds = %7, %1, %4, %10
%13 = phi i8* [ %0, %10 ], [ null, %4 ], [ null, %1 ], [ null, %7 ]
ret i8* %13
}