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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ h1(char *);
int /*<<< orphan*/ html_begin(char *);
int /*<<< orphan*/ html_end();
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
void authenticate(char *dest) {
  FILE *access;
  char s[80];
  short FOUND = 0;
  access = fopen("/usr/local/etc/httpd/conf/mail.conf", "r");
  while ((fgets(s, 80, access) != NULL) && (!FOUND)) {
    s[strlen(s) - 1] = '\0';
    if (!strcmp(s, dest))
      FOUND = 1;
  }
  if (!FOUND) {
    html_begin("Unauthorized Destination");
    h1("Unauthorized Destination");
    html_end();
    exit(1);
  }
}


x86 assembly (clang, -O0):
<authenticate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movw   $0x0,-0x62(%rbp)
lea    0xe67(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x50,%esi
call   1050 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x63(%rbp)
je     11da <authenticate+0x5a>
cmpw   $0x0,-0x62(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x63(%rbp)
mov    -0x63(%rbp),%al
test   $0x1,%al
jne    11ea <authenticate+0x6a>
jmp    121e <authenticate+0x9e>
lea    -0x60(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x60(%rbp,%rax,1)
lea    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1219 <authenticate+0x99>
movw   $0x1,-0x62(%rbp)
jmp    11a9 <authenticate+0x29>
cmpw   $0x0,-0x62(%rbp)
jne    1252 <authenticate+0xd2>
lea    0xdf6(%rip),%rdi
call   1070 <html_begin@plt>
lea    0xdea(%rip),%rdi
call   1080 <h1@plt>
mov    $0x0,%al
call   1030 <html_end@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<authenticate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%r14
lea    0xe6c(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1204 <authenticate+0x84>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f5 <authenticate+0x75>
test   %ebp,%ebp
jne    11c0 <authenticate+0x40>
test   %ebp,%ebp
jne    1204 <authenticate+0x84>
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe1b(%rip),%rbx
mov    %rbx,%rdi
call   1070 <html_begin@plt>
mov    %rbx,%rdi
call   1080 <h1@plt>
xor    %eax,%eax
call   1030 <html_end@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"/usr/local/etc/httpd/conf/mail.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Unauthorized Destination\00"
define void @authenticate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [80 x i8]
%5 = alloca i16
store i8* %0, i8** %2
store i16 0, i16* %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
br label %7
7: ; preds = %29, %1
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%9 = load i32*, i32** %3
%10 = call i32* @fgets(i8* %8, i32 80, i32* %9)
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = load i16, i16* %5
%14 = icmp ne i16 %13, 0
%15 = xor i1 %14, true
br label %16
16: ; preds = %12, %7
%17 = phi i1 [ false, %7 ], [ %15, %12 ]
br i1 %17, label %18, label %30
18: ; preds = %16
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%25 = load i8*, i8** %2
%26 = call i32 @strcmp(i8* %24, i8* %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %18
store i16 1, i16* %5
br label %29
29: ; preds = %28, %18
br label %7
30: ; preds = %16
%31 = load i16, i16* %5
%32 = icmp ne i16 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %30
%34 = call i32 @html_begin(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @h1(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 (...) @html_end()
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [36 x i8] c"/usr/local/etc/httpd/conf/mail.conf\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [25 x i8] c"Unauthorized Destination\00"
define void @authenticate(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %18, label %7
7: ; preds = %1, %7
%8 = call i32 @strlen(i8* %3)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @strcmp(i8* %3, i8* dereferenceable(1) %0)
%13 = icmp ne i32 %12, 0
%14 = call i32* @fgets(i8* %3, i32 80, i32* %4)
%15 = icmp ne i32* %14, null
%16 = select i1 %15, i1 %13, i1 false
br i1 %16, label %7, label %17
17: ; preds = %7
br i1 %13, label %18, label %23
18: ; preds = %1, %17
%19 = call i32 @html_begin(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @h1(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (...) @html_end()
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
ret void
}