#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 */
int /*<<< orphan*/ free(char *);
char *get_header(char const *);
int sscanf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char const *);
int is_common_authorized(const char *header, const char *userpass64) {
  char *req_auth = NULL;
  char req_scheme[32];
  char req_encoded[32];
  int result = 0;
  char *reason = "unknown";
  if (!userpass64) {
    result = 1;
    goto exit;
  }
  req_auth = get_header(header);
  if (!req_auth) {
    reason = "header does not exists";
    goto exit;
  }
  if (sscanf(req_auth, "%31s %31s", req_scheme, req_encoded) < 2) {
    reason = "scanf fail";
    ((void)(0));
    goto exit;
  }
  if (strcmp(req_scheme, "Basic")) {
    ((void)(0));
    reason = "auth scheme does not supported";
    goto exit;
  }
  if (strcmp(req_encoded, userpass64) == 0) {
    result = 1;
  } else {
    reason = "user/pass invalid";
  }
exit:
  if (req_auth)
    free(req_auth);
  if (!result) {
    ((void)(0));
  } else {
    ((void)(0));
  }
  return result;
}


x86 assembly (clang, -O0):
<is_common_authorized>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1181 <is_common_authorized+0x41>
movl   $0x1,-0x64(%rbp)
jmp    1237 <is_common_authorized+0xf7>
mov    -0x8(%rbp),%rdi
call   1040 <get_header@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a9 <is_common_authorized+0x69>
lea    0xe68(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1237 <is_common_authorized+0xf7>
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    0xe63(%rip),%rsi
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jge    11da <is_common_authorized+0x9a>
lea    0xe58(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1237 <is_common_authorized+0xf7>
lea    -0x40(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1204 <is_common_authorized+0xc4>
lea    0xe3f(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1237 <is_common_authorized+0xf7>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1227 <is_common_authorized+0xe7>
movl   $0x1,-0x64(%rbp)
jmp    1232 <is_common_authorized+0xf2>
lea    0xe2b(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1237 <is_common_authorized+0xf7>
cmpq   $0x0,-0x18(%rbp)
je     124b <is_common_authorized+0x10b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x64(%rbp)
jne    125a <is_common_authorized+0x11a>
jmp    125f <is_common_authorized+0x11f>
jmp    125f <is_common_authorized+0x11f>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_common_authorized>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
test   %rsi,%rsi
je     11af <is_common_authorized+0x6f>
mov    %rsi,%rbx
call   1040 <get_header@plt>
test   %rax,%rax
je     11b6 <is_common_authorized+0x76>
mov    %rax,%r14
lea    0xe9c(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rsp,%rcx
mov    %rax,%rdi
call   1060 <sscanf@plt>
xor    %ebp,%ebp
cmp    $0x2,%eax
jl     11a5 <is_common_authorized+0x65>
lea    0xe88(%rip),%rsi
lea    0x20(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11a5 <is_common_authorized+0x65>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %r14,%rdi
call   1030 <free@plt>
jmp    11b8 <is_common_authorized+0x78>
mov    $0x1,%ebp
jmp    11b8 <is_common_authorized+0x78>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"unknown\00"
@.str.1 = [23 x i8] c"header does not exists\00"
@.str.2 = [10 x i8] c"%31s %31s\00"
@.str.3 = [11 x i8] c"scanf fail\00"
@.str.4 = [6 x i8] c"Basic\00"
@.str.5 = [31 x i8] c"auth scheme does not supported\00"
@.str.6 = [18 x i8] c"user/pass invalid\00"
define i32 @is_common_authorized(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
store i32 0, i32* %8
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 1, i32* %8
br label %39
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i8* @get_header(i8* %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %13
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %39
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%23 = call i32 @sscanf(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %21, i8* %22)
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %26
25: ; preds = %19
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %39
26: ; preds = %19
%27 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0), i8** %9
br label %39
31: ; preds = %26
%32 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%33 = load i8*, i8** %4
%34 = call i64 @strcmp(i8* %32, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 1, i32* %8
br label %38
37: ; preds = %31
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8** %9
br label %38
38: ; preds = %37, %36
br label %39
39: ; preds = %38, %30, %25, %18, %12
%40 = load i8*, i8** %5
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i8*, i8** %5
%44 = call i32 @free(i8* %43)
br label %45
45: ; preds = %42, %39
%46 = load i32, i32* %8
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %45
br label %50
49: ; preds = %45
br label %50
50: ; preds = %49, %48
%51 = load i32, i32* %8
ret i32 %51
}

LLVM IR (-O2):
@.str.2 = [10 x i8] c"%31s %31s\00"
@.str.4 = [6 x i8] c"Basic\00"
define i32 @is_common_authorized(i8* %0, i8* %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %1, null
br i1 %7, label %24, label %8
8: ; preds = %2
%9 = tail call i8* @get_header(i8* %0)
%10 = icmp eq i8* %9, null
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %6)
%13 = icmp slt i32 %12, 2
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = call i64 @strcmp(i8* %6, i8* %1)
%19 = icmp eq i64 %18, 0
%20 = zext i1 %19 to i32
br label %21
21: ; preds = %11, %14, %17
%22 = phi i32 [ %20, %17 ], [ 0, %14 ], [ 0, %11 ]
%23 = call i32 @free(i8* %9)
br label %24
24: ; preds = %2, %8, %21
%25 = phi i32 [ %22, %21 ], [ 1, %2 ], [ 0, %8 ]
ret i32 %25
}