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

/* Variables and functions */
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int getauthfromURL(char *url, char *auth) {
  char *pos;
  *auth = 0;
  if (!(strncasecmp(url, "http://", 7)))
    url += 7;
  if (!(strncasecmp(url, "ftp://", 6)))
    url += 6;
  if ((pos = strchr(url, '@'))) {
    int i;
    for (i = 0; i < pos - url; i++) {
      if (url[i] == '/')
        return 0;
    }
    strncpy(auth, url, pos - url);
    auth[pos - url] = 0;
    strcpy(url, pos + 1);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<getauthfromURL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1181 <getauthfromURL+0x41>
mov    -0x10(%rbp),%rax
add    $0x7,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x6,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%eax
jne    11ab <getauthfromURL+0x6b>
mov    -0x10(%rbp),%rax
add    $0x6,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1264 <getauthfromURL+0x124>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
cmp    %rcx,%rax
jge    121a <getauthfromURL+0xda>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1207 <getauthfromURL+0xc7>
movl   $0x0,-0x4(%rbp)
jmp    126b <getauthfromURL+0x12b>
jmp    120c <getauthfromURL+0xcc>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ce <getauthfromURL+0x8e>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    126b <getauthfromURL+0x12b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getauthfromURL>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    %rdi,%rbx
movb   $0x0,(%rsi)
lea    0xea5(%rip),%rsi
mov    $0x7,%edx
call   1060 <strncasecmp@plt>
xor    %r13d,%r13d
test   %eax,%eax
mov    $0x7,%r14d
cmovne %r13,%r14
lea    (%rbx,%r14,1),%r12
lea    0xe89(%rip),%rsi
mov    %r12,%rdi
mov    $0x6,%edx
call   1060 <strncasecmp@plt>
test   %eax,%eax
mov    $0x6,%r15d
cmovne %r13,%r15
add    %r15,%r12
mov    %r12,%rdi
mov    $0x40,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120a <getauthfromURL+0xca>
mov    %rax,%r13
mov    %rbp,%rcx
mov    %rax,%rbp
sub    %r12,%rbp
test   %rbp,%rbp
jle    11e0 <getauthfromURL+0xa0>
add    %r15,%r14
mov    %r13,%rax
sub    %rbx,%rax
nopw   0x0(%rax,%rax,1)
cmpb   $0x2f,(%rbx,%r14,1)
je     120a <getauthfromURL+0xca>
add    $0x1,%r14
cmp    %r14,%rax
jne    11d0 <getauthfromURL+0x90>
mov    %rcx,%rbx
mov    %rcx,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
add    $0x1,%r13
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    $0x1,%eax
jmp    120c <getauthfromURL+0xcc>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"http://\00"
@.str.1 = [7 x i8] c"ftp://\00"
define i32 @getauthfromURL(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
store i8 0, i8* %8
%9 = load i8*, i8** %4
%10 = call i32 @strncasecmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%11 = icmp ne i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 7
store i8* %14, i8** %4
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %4
%17 = call i32 @strncasecmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i64 6
store i8* %21, i8** %4
br label %22
22: ; preds = %19, %15
%23 = load i8*, i8** %4
%24 = call i8* @strchr(i8* %23, i8 signext 64)
store i8* %24, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %70
26: ; preds = %22
store i32 0, i32* %7
br label %27
27: ; preds = %46, %26
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = load i8*, i8** %6
%31 = load i8*, i8** %4
%32 = ptrtoint i8* %30 to i64
%33 = ptrtoint i8* %31 to i64
%34 = sub i64 %32, %33
%35 = icmp slt i64 %29, %34
br i1 %35, label %36, label %49
36: ; preds = %27
%37 = load i8*, i8** %4
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 47
br i1 %43, label %44, label %45
44: ; preds = %36
store i32 0, i32* %3
br label %71
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %27
49: ; preds = %27
%50 = load i8*, i8** %5
%51 = load i8*, i8** %4
%52 = load i8*, i8** %6
%53 = load i8*, i8** %4
%54 = ptrtoint i8* %52 to i64
%55 = ptrtoint i8* %53 to i64
%56 = sub i64 %54, %55
%57 = trunc i64 %56 to i32
%58 = call i32 @strncpy(i8* %50, i8* %51, i32 %57)
%59 = load i8*, i8** %5
%60 = load i8*, i8** %6
%61 = load i8*, i8** %4
%62 = ptrtoint i8* %60 to i64
%63 = ptrtoint i8* %61 to i64
%64 = sub i64 %62, %63
%65 = getelementptr inbounds i8, i8* %59, i64 %64
store i8 0, i8* %65
%66 = load i8*, i8** %4
%67 = load i8*, i8** %6
%68 = getelementptr inbounds i8, i8* %67, i64 1
%69 = call i32 @strcpy(i8* %66, i8* %68)
store i32 1, i32* %3
br label %71
70: ; preds = %22
store i32 0, i32* %3
br label %71
71: ; preds = %70, %49, %44
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [8 x i8] c"http://\00"
@.str.1 = [7 x i8] c"ftp://\00"
define i32 @getauthfromURL(i8* %0, i8* %1) {
store i8 0, i8* %1
%3 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i64 7, i64 0
%6 = getelementptr i8, i8* %0, i64 %5
%7 = tail call i32 @strncasecmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i64 6, i64 0
%10 = getelementptr i8, i8* %6, i64 %9
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 64)
%12 = icmp eq i8* %11, null
br i1 %12, label %32, label %13
13: ; preds = %2
%14 = ptrtoint i8* %11 to i64
%15 = ptrtoint i8* %10 to i64
%16 = sub i64 %14, %15
%17 = icmp sgt i64 %16, 0
br i1 %17, label %20, label %26
18: ; preds = %20
%19 = icmp eq i64 %25, %16
br i1 %19, label %26, label %20
20: ; preds = %13, %18
%21 = phi i64 [ %25, %18 ], [ 0, %13 ]
%22 = getelementptr inbounds i8, i8* %10, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 47
%25 = add nuw nsw i64 %21, 1
br i1 %24, label %32, label %18
26: ; preds = %18, %13
%27 = trunc i64 %16 to i32
%28 = tail call i32 @strncpy(i8* %1, i8* %10, i32 %27)
%29 = getelementptr inbounds i8, i8* %1, i64 %16
store i8 0, i8* %29
%30 = getelementptr inbounds i8, i8* %11, i64 1
%31 = tail call i32 @strcpy(i8* %10, i8* %30)
br label %32
32: ; preds = %20, %2, %26
%33 = phi i32 [ 1, %26 ], [ 0, %2 ], [ 0, %20 ]
ret i32 %33
}