#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 */
struct rtsp_client {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ rtsp_decode_base64(char *);
char *rtsp_get_header(struct rtsp_client *, char *, int /*<<< orphan*/);
char *strchr(char *, char);
char *strdup(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *rtsp_basic_auth_get_username_password(struct rtsp_client *c,
                                            char **password) {
  const char *auth;
  char *decoded;
  char *username;
  char *p;
  if (c == NULL)
    return NULL;
  auth = rtsp_get_header(c, "Authorization", 0);
  if (auth == NULL)
    return NULL;
  if (strncmp(auth, "Basic ", 6) != 0)
    return NULL;
  decoded = strdup(auth + 6);
  rtsp_decode_base64(decoded);
  p = strchr(decoded, ':');
  if (p == NULL) {
    free(decoded);
    return NULL;
  }
  *p++ = '\0';
  username = strdup(decoded);
  *password = strdup(p);
  free(decoded);
  return username;
}


x86 assembly (clang, -O0):
<rtsp_basic_auth_get_username_password>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1188 <rtsp_basic_auth_get_username_password+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1272 <rtsp_basic_auth_get_username_password+0x112>
mov    -0x10(%rbp),%rdi
lea    0xe6d(%rip),%rsi
xor    %edx,%edx
call   1050 <rtsp_get_header@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <rtsp_basic_auth_get_username_password+0x56>
movq   $0x0,-0x8(%rbp)
jmp    1272 <rtsp_basic_auth_get_username_password+0x112>
mov    -0x20(%rbp),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     11e2 <rtsp_basic_auth_get_username_password+0x82>
movq   $0x0,-0x8(%rbp)
jmp    1272 <rtsp_basic_auth_get_username_password+0x112>
mov    -0x20(%rbp),%rdi
add    $0x6,%rdi
call   1080 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <rtsp_decode_base64@plt>
mov    -0x28(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122f <rtsp_basic_auth_get_username_password+0xcf>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1272 <rtsp_basic_auth_get_username_password+0x112>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtsp_basic_auth_get_username_password>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a2 <rtsp_basic_auth_get_username_password+0x42>
mov    %rsi,%r14
lea    0xe89(%rip),%rsi
xor    %r12d,%r12d
xor    %edx,%edx
call   1050 <rtsp_get_header@plt>
test   %rax,%rax
je     11a5 <rtsp_basic_auth_get_username_password+0x45>
mov    %rax,%rbx
lea    0xe7e(%rip),%rsi
mov    %rax,%rdi
mov    $0x6,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11b4 <rtsp_basic_auth_get_username_password+0x54>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
add    $0x6,%rbx
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1070 <rtsp_decode_base64@plt>
mov    %r15,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11ff <rtsp_basic_auth_get_username_password+0x9f>
mov    %rax,%rbx
add    $0x1,%rbx
movb   $0x0,(%rax)
mov    %r15,%rdi
call   1080 <strdup@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1080 <strdup@plt>
mov    %rax,(%r14)
jmp    1202 <rtsp_basic_auth_get_username_password+0xa2>
xor    %r12d,%r12d
mov    %r15,%rdi
call   1030 <free@plt>
jmp    11a5 <rtsp_basic_auth_get_username_password+0x45>

LLVM IR (-O0):
%struct.rtsp_client = type { i32 }
@.str = [14 x i8] c"Authorization\00"
@.str.1 = [7 x i8] c"Basic \00"
define i8* @rtsp_basic_auth_get_username_password(%struct.rtsp_client* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca %struct.rtsp_client*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store %struct.rtsp_client* %0, %struct.rtsp_client** %4
store i8** %1, i8*** %5
%10 = load %struct.rtsp_client*, %struct.rtsp_client** %4
%11 = icmp eq %struct.rtsp_client* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %48
13: ; preds = %2
%14 = load %struct.rtsp_client*, %struct.rtsp_client** %4
%15 = call i8* @rtsp_get_header(%struct.rtsp_client* %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
store i8* null, i8** %3
br label %48
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
store i8* null, i8** %3
br label %48
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 6
%27 = call i8* @strdup(i8* %26)
store i8* %27, i8** %7
%28 = load i8*, i8** %7
%29 = call i32 @rtsp_decode_base64(i8* %28)
%30 = load i8*, i8** %7
%31 = call i8* @strchr(i8* %30, i8 signext 58)
store i8* %31, i8** %9
%32 = load i8*, i8** %9
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = load i8*, i8** %7
%36 = call i32 @free(i8* %35)
store i8* null, i8** %3
br label %48
37: ; preds = %24
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %9
store i8 0, i8* %38
%40 = load i8*, i8** %7
%41 = call i8* @strdup(i8* %40)
store i8* %41, i8** %8
%42 = load i8*, i8** %9
%43 = call i8* @strdup(i8* %42)
%44 = load i8**, i8*** %5
store i8* %43, i8** %44
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %8
store i8* %47, i8** %3
br label %48
48: ; preds = %37, %34, %23, %18, %12
%49 = load i8*, i8** %3
ret i8* %49
}

LLVM IR (-O2):
%struct.rtsp_client = type { i32 }
@.str = [14 x i8] c"Authorization\00"
@.str.1 = [7 x i8] c"Basic \00"
define noalias i8* @rtsp_basic_auth_get_username_password(%struct.rtsp_client* %0, i8** nocapture writeonly %1) {
%3 = icmp eq %struct.rtsp_client* %0, null
br i1 %3, label %23, label %4
4: ; preds = %2
%5 = tail call i8* @rtsp_get_header(%struct.rtsp_client* %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = icmp eq i8* %5, null
br i1 %6, label %23, label %7
7: ; preds = %4
%8 = tail call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %5, i64 6
%12 = tail call i8* @strdup(i8* %11)
%13 = tail call i32 @rtsp_decode_base64(i8* %12)
%14 = tail call i8* @strchr(i8* dereferenceable(1) %12, i8 signext 58)
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %14
%18 = tail call i8* @strdup(i8* %12)
%19 = tail call i8* @strdup(i8* %17)
store i8* %19, i8** %1
br label %20
20: ; preds = %10, %16
%21 = phi i8* [ %18, %16 ], [ null, %10 ]
%22 = tail call i32 @free(i8* %12)
br label %23
23: ; preds = %20, %7, %4, %2
%24 = phi i8* [ null, %2 ], [ null, %4 ], [ null, %7 ], [ %21, %20 ]
ret i8* %24
}