#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*/ scheme;

/* Variables and functions */
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int is_uri_scheme(char *p) {
  char *scheme[] = {"http:", "https:", "file:", "ftp:", "git:", "gopher:"};
  int i, len, nschemes = sizeof(scheme) / sizeof(scheme[0]);
  for (i = 0; i < nschemes; ++i) {
    len = strlen(scheme[i]);
    if (!strncmp(p, scheme[i], len))
      return len;
  }
  return 0;
}


x86 assembly (clang, -O0):
<is_uri_scheme>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1050 <memset@plt>
lea    0xead(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xea4(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe9f(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe99(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x6,-0x4c(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    11f5 <is_uri_scheme+0xc5>
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x44(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rsi
mov    -0x48(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11e2 <is_uri_scheme+0xb2>
mov    -0x48(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11fc <is_uri_scheme+0xcc>
jmp    11e7 <is_uri_scheme+0xb7>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    119c <is_uri_scheme+0x6c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_uri_scheme>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xed2(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11fe <is_uri_scheme+0xde>
lea    0xeb2(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11fe <is_uri_scheme+0xde>
lea    0xe93(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11fe <is_uri_scheme+0xde>
lea    0xe77(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11fe <is_uri_scheme+0xde>
lea    0xe5a(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     11fe <is_uri_scheme+0xde>
lea    0xe3d(%rip),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
xor    %ebp,%ebp
test   %eax,%eax
cmove  %ebx,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"http:\00"
@.str.1 = [7 x i8] c"https:\00"
@.str.2 = [6 x i8] c"file:\00"
@.str.3 = [5 x i8] c"ftp:\00"
@.str.4 = [5 x i8] c"git:\00"
@.str.5 = [8 x i8] c"gopher:\00"
define i32 @is_uri_scheme(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [6 x i8*]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
%8 = bitcast [6 x i8*]* %4 to i8*
%9 = bitcast i8* %8 to [6 x i8*]*
%10 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8** %11
%12 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %12
%13 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 3
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0), i8** %13
%14 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 4
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8** %14
%15 = getelementptr inbounds [6 x i8*], [6 x i8*]* %9, i32 0, i32 5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8** %15
store i32 6, i32* %7
store i32 0, i32* %5
br label %16
16: ; preds = %37, %1
%17 = load i32, i32* %5
%18 = load i32, i32* %7
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %40
20: ; preds = %16
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %6
%26 = load i8*, i8** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [6 x i8*], [6 x i8*]* %4, i64 0, i64 %28
%30 = load i8*, i8** %29
%31 = load i32, i32* %6
%32 = call i32 @strncmp(i8* %26, i8* %30, i32 %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %20
%35 = load i32, i32* %6
store i32 %35, i32* %2
br label %41
36: ; preds = %20
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %16
40: ; preds = %16
store i32 0, i32* %2
br label %41
41: ; preds = %40, %34
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [6 x i8] c"http:\00"
@.str.1 = [7 x i8] c"https:\00"
@.str.2 = [6 x i8] c"file:\00"
@.str.3 = [5 x i8] c"ftp:\00"
@.str.4 = [5 x i8] c"git:\00"
@.str.5 = [8 x i8] c"gopher:\00"
define i32 @is_uri_scheme(i8* %0) {
%2 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %1
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %5
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %9
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %13
%18 = tail call i32 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%19 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = tail call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%23 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 %22, i32 0
br label %26
26: ; preds = %21, %17, %13, %9, %5, %1
%27 = phi i32 [ %2, %1 ], [ %6, %5 ], [ %10, %9 ], [ %14, %13 ], [ %18, %17 ], [ %25, %21 ]
ret i32 %27
}