#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*/ HTTP_b64_unencode(unsigned char *, unsigned char *);
unsigned char SPI_Ethernet_getByte();
scalar_t__ memcmp(unsigned char *, char *, int);
scalar_t__ strcmp(unsigned char *, unsigned char *);
unsigned char HTTP_basicRealm(unsigned int l, unsigned char *passwd) {
  unsigned int len = 0;
  unsigned int i;
  unsigned char auth[128];
  unsigned char login[30 + 1];
  unsigned char found;
  i = 0;
  found = 0;
  while (l--) {
    auth[i] = SPI_Ethernet_getByte();
    if ((auth[i] < 32) || (i == 128 - 1)) {
      if (memcmp(auth, "Authorization: Basic ",
                 sizeof("Authorization: Basic ") - 1) == 0) {
        auth[i] = 0;
        HTTP_b64_unencode(auth + sizeof("Authorization: Basic ") - 1, login);
        if (strcmp(login, passwd) == 0) {
          found = 1;
        }
        break;
      }
      i = 0;
    } else {
      i++;
    }
  }
  return (found);
}


x86 assembly (clang, -O0):
<HTTP_basicRealm>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0xc1(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     1234 <HTTP_basicRealm+0xf4>
mov    $0x0,%al
call   1040 <SPI_Ethernet_getByte@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
mov    %cl,-0xa0(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
movzbl -0xa0(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jl     11ac <HTTP_basicRealm+0x6c>
cmpl   $0x7f,-0x18(%rbp)
jne    1226 <HTTP_basicRealm+0xe6>
lea    -0xa0(%rbp),%rdi
lea    0xe46(%rip),%rsi
mov    $0x15,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
jne    121a <HTTP_basicRealm+0xda>
mov    -0x18(%rbp),%eax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
add    $0x16,%rdi
add    $0xffffffffffffffff,%rdi
lea    -0xc0(%rbp),%rsi
call   1030 <HTTP_b64_unencode@plt>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1215 <HTTP_basicRealm+0xd5>
movb   $0x1,-0xc1(%rbp)
jmp    1234 <HTTP_basicRealm+0xf4>
movl   $0x0,-0x18(%rbp)
jmp    122f <HTTP_basicRealm+0xef>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1167 <HTTP_basicRealm+0x27>
movzbl -0xc1(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTTP_basicRealm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
xor    %eax,%eax
test   %edi,%edi
je     11d7 <HTTP_basicRealm+0x97>
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe99(%rip),%r15
lea    0x20(%rsp),%r12
xor    %ebx,%ebx
jmp    118c <HTTP_basicRealm+0x4c>
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x15,%edx
call   1050 <memcmp@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11b0 <HTTP_basicRealm+0x70>
add    $0xffffffff,%ebp
je     11ac <HTTP_basicRealm+0x6c>
xor    %eax,%eax
call   1040 <SPI_Ethernet_getByte@plt>
mov    %ebx,%r13d
mov    %al,0x20(%rsp,%r13,1)
cmp    $0x20,%al
jb     1170 <HTTP_basicRealm+0x30>
cmp    $0x7f,%ebx
je     1170 <HTTP_basicRealm+0x30>
add    $0x1,%ebx
add    $0xffffffff,%ebp
jne    118c <HTTP_basicRealm+0x4c>
xor    %eax,%eax
jmp    11d7 <HTTP_basicRealm+0x97>
movb   $0x0,0x20(%rsp,%r13,1)
lea    0x35(%rsp),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1030 <HTTP_b64_unencode@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
sete   %al
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Authorization: Basic \00"
define zeroext i8 @HTTP_basicRealm(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca [31 x i8]
%9 = alloca i8
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i8 0, i8* %9
br label %10
10: ; preds = %51, %2
%11 = load i32, i32* %3
%12 = add i32 %11, -1
store i32 %12, i32* %3
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %52
14: ; preds = %10
%15 = call zeroext i8 (...) @SPI_Ethernet_getByte()
%16 = load i32, i32* %6
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %17
store i8 %15, i8* %18
%19 = load i32, i32* %6
%20 = zext i32 %19 to i64
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = icmp slt i32 %23, 32
br i1 %24, label %28, label %25
25: ; preds = %14
%26 = load i32, i32* %6
%27 = icmp eq i32 %26, 127
br i1 %27, label %28, label %48
28: ; preds = %25, %14
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%30 = call i64 @memcmp(i8* %29, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 21)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i32, i32* %6
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%37 = getelementptr inbounds i8, i8* %36, i64 22
%38 = getelementptr inbounds i8, i8* %37, i64 -1
%39 = getelementptr inbounds [31 x i8], [31 x i8]* %8, i64 0, i64 0
%40 = call i32 @HTTP_b64_unencode(i8* %38, i8* %39)
%41 = getelementptr inbounds [31 x i8], [31 x i8]* %8, i64 0, i64 0
%42 = load i8*, i8** %4
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %32
store i8 1, i8* %9
br label %46
46: ; preds = %45, %32
br label %52
47: ; preds = %28
store i32 0, i32* %6
br label %51
48: ; preds = %25
%49 = load i32, i32* %6
%50 = add i32 %49, 1
store i32 %50, i32* %6
br label %51
51: ; preds = %48, %47
br label %10
52: ; preds = %46, %10
%53 = load i8, i8* %9
ret i8 %53
}

LLVM IR (-O2):
@.str = [22 x i8] c"Authorization: Basic \00"
define zeroext i8 @HTTP_basicRealm(i32 %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [31 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [31 x i8], [31 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 0
br i1 %7, label %34, label %8
8: ; preds = %2, %31
%9 = phi i32 [ %11, %31 ], [ %0, %2 ]
%10 = phi i32 [ %32, %31 ], [ 0, %2 ]
%11 = add i32 %9, -1
%12 = call zeroext i8 (...) @SPI_Ethernet_getByte()
%13 = zext i32 %10 to i64
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %13
store i8 %12, i8* %14
%15 = icmp ult i8 %12, 32
%16 = icmp eq i32 %10, 127
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %18, label %29
18: ; preds = %8
%19 = call i64 @memcmp(i8* %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 21)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = zext i32 %10 to i64
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 21
%25 = call i32 @HTTP_b64_unencode(i8* %24, i8* %6)
%26 = call i64 @strcmp(i8* %6, i8* %1)
%27 = icmp eq i64 %26, 0
%28 = zext i1 %27 to i8
br label %34
29: ; preds = %8
%30 = add i32 %10, 1
br label %31
31: ; preds = %18, %29
%32 = phi i32 [ %30, %29 ], [ 0, %18 ]
%33 = icmp eq i32 %11, 0
br i1 %33, label %34, label %8
34: ; preds = %31, %2, %21
%35 = phi i8 [ %28, %21 ], [ 0, %2 ], [ 0, %31 ]
ret i8 %35
}