#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 O_APPEND;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int getpid();
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
int /*<<< orphan*/ write(int, char *, int);
void logger(int type, char *s1, char *s2, int socket_fd) {
  int writeLog = 0;
  int fd;
  char logbuffer[8096 * 2];
  switch (type) {
  case 42:
    (void)sprintf(logbuffer, "ERROR: %s:%s Errno=%d exiting pid=%d", s1, s2,
                  errno, getpid());
    break;
  case 403:
    (void)write(socket_fd,
                "HTTP/1.1 403 Forbidden\nContent-Length: 185\nConnection: "
                "close\nContent-Type: text/html\n\n<html><head>\n<title>403 "
                "Forbidden</title>\n</head><body>\n<h1>Forbidden</h1>\nThe "
                "requested URL, file type or operation is not allowed on this "
                "simple static file webserver.\n</body></html>\n",
                271);
    (void)sprintf(logbuffer, "FORBIDDEN: %s:%s", s1, s2);
    break;
  case 404:
    (void)write(socket_fd,
                "HTTP/1.1 404 Not Found\nContent-Length: 136\nConnection: "
                "close\nContent-Type: text/html\n\n<html><head>\n<title>404 "
                "Not Found</title>\n</head><body>\n<h1>Not Found</h1>\nThe "
                "requested URL was not found on this server.\n</body></html>\n",
                224);
    (void)sprintf(logbuffer, "NOT FOUND: %s:%s", s1, s2);
    break;
  case 44:
    break;
  }
  if (writeLog == 1) {
    if ((fd = open("bb.log", O_CREAT | O_WRONLY | O_APPEND, 0644)) >= 0) {
      (void)close(fd);
    }
  }
  if (type == 42 || type == 404 || type == 403)
    exit(3);
}


x86 assembly (clang, -O0):
<logger>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3f90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3f74(%rbp)
sub    $0x2a,%eax
je     11d7 <logger+0x77>
jmp    1197 <logger+0x37>
mov    -0x3f74(%rbp),%eax
sub    $0x2c,%eax
je     12af <logger+0x14f>
jmp    11ab <logger+0x4b>
mov    -0x3f74(%rbp),%eax
sub    $0x193,%eax
je     1243 <logger+0xe3>
jmp    11c1 <logger+0x61>
mov    -0x3f74(%rbp),%eax
sub    $0x194,%eax
je     1279 <logger+0x119>
jmp    12b4 <logger+0x154>
lea    -0x3f70(%rbp),%rax
mov    %rax,-0x3f90(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x3f88(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x3f80(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3f78(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x3f90(%rbp),%rdi
mov    -0x3f88(%rbp),%rdx
mov    -0x3f80(%rbp),%rcx
mov    -0x3f78(%rbp),%r8d
mov    %eax,%r9d
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12b4 <logger+0x154>
mov    -0x1c(%rbp),%edi
lea    0xdd8(%rip),%rsi
mov    $0x10f,%edx
call   1030 <write@plt>
lea    -0x3f70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xec8(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12b4 <logger+0x154>
mov    -0x1c(%rbp),%edi
lea    0xec3(%rip),%rsi
mov    $0xe0,%edx
call   1030 <write@plt>
lea    -0x3f70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xf84(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    12b4 <logger+0x154>
jmp    12b4 <logger+0x154>
cmpl   $0x1,-0x20(%rbp)
jne    1303 <logger+0x1a3>
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    0x2cfa(%rip),%rax
or     (%rax),%esi
mov    0x2ce9(%rip),%rax
or     (%rax),%esi
lea    0xf58(%rip),%rdi
mov    $0x1a4,%edx
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jl     12fe <logger+0x19e>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
jmp    1303 <logger+0x1a3>
cmpl   $0x2a,-0x4(%rbp)
je     1327 <logger+0x1c7>
cmpl   $0x194,-0x4(%rbp)
je     1327 <logger+0x1c7>
cmpl   $0x193,-0x4(%rbp)
jne    1331 <logger+0x1d1>
mov    $0x3,%edi
call   1080 <exit@plt>
add    $0x3f90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f40,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
cmp    $0x194,%edi
je     1172 <logger+0x32>
cmp    $0x193,%edi
je     118e <logger+0x4e>
cmp    $0x2a,%edi
je     11c2 <logger+0x82>
add    $0x3f40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xfcd(%rip),%rsi
mov    %ecx,%edi
mov    $0xe0,%edx
call   1030 <write@plt>
lea    0x109b(%rip),%rsi
jmp    11a8 <logger+0x68>
lea    0xe90(%rip),%rsi
mov    %ecx,%edi
mov    $0x10f,%edx
call   1030 <write@plt>
lea    0xf8d(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    $0x3,%edi
call   1060 <exit@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe27(%rip),%rsi
mov    %rsp,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    $0x3,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"ERROR: %s:%s Errno=%d exiting pid=%d\00"
@errno = global i32 0
@.str.1 = [272 x i8] c"HTTP/1.1 403 Forbidden\0AContent-Length: 185\0AConnection: close\0AContent-Type: text/html\0A\0A<html><head>\0A<title>403 Forbidden</title>\0A</head><body>\0A<h1>Forbidden</h1>\0AThe requested URL, file type or operation is not allowed on this simple static file webserver.\0A</body></html>\0A\00"
@.str.2 = [17 x i8] c"FORBIDDEN: %s:%s\00"
@.str.3 = [225 x i8] c"HTTP/1.1 404 Not Found\0AContent-Length: 136\0AConnection: close\0AContent-Type: text/html\0A\0A<html><head>\0A<title>404 Not Found</title>\0A</head><body>\0A<h1>Not Found</h1>\0AThe requested URL was not found on this server.\0A</body></html>\0A\00"
@.str.4 = [17 x i8] c"NOT FOUND: %s:%s\00"
@.str.5 = [7 x i8] c"bb.log\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
define void @logger(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [16192 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
%12 = load i32, i32* %5
switch i32 %12, label %35 [
i32 42, label %13
i32 403, label %20
i32 404, label %27
i32 44, label %34
]
13: ; preds = %4
%14 = getelementptr inbounds [16192 x i8], [16192 x i8]* %11, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = load i8*, i8** %7
%17 = load i32, i32* @errno
%18 = call i32 (...) @getpid()
%19 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %16, i32 %17, i32 %18)
br label %35
20: ; preds = %4
%21 = load i32, i32* %8
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([272 x i8], [272 x i8]* @.str.1, i64 0, i64 0), i32 271)
%23 = getelementptr inbounds [16192 x i8], [16192 x i8]* %11, i64 0, i64 0
%24 = load i8*, i8** %6
%25 = load i8*, i8** %7
%26 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25)
br label %35
27: ; preds = %4
%28 = load i32, i32* %8
%29 = call i32 @write(i32 %28, i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str.3, i64 0, i64 0), i32 224)
%30 = getelementptr inbounds [16192 x i8], [16192 x i8]* %11, i64 0, i64 0
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %31, i8* %32)
br label %35
34: ; preds = %4
br label %35
35: ; preds = %4, %34, %27, %20, %13
%36 = load i32, i32* %9
%37 = icmp eq i32 %36, 1
br i1 %37, label %38, label %50
38: ; preds = %35
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @O_WRONLY
%41 = or i32 %39, %40
%42 = load i32, i32* @O_APPEND
%43 = or i32 %41, %42
%44 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %43, i32 420)
store i32 %44, i32* %10
%45 = icmp sge i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %38
%47 = load i32, i32* %10
%48 = call i32 @close(i32 %47)
br label %49
49: ; preds = %46, %38
br label %50
50: ; preds = %49, %35
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 42
br i1 %52, label %59, label %53
53: ; preds = %50
%54 = load i32, i32* %5
%55 = icmp eq i32 %54, 404
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i32, i32* %5
%58 = icmp eq i32 %57, 403
br i1 %58, label %59, label %61
59: ; preds = %56, %53, %50
%60 = call i32 @exit(i32 3)
unreachable
61: ; preds = %56
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"ERROR: %s:%s Errno=%d exiting pid=%d\00"
@errno = global i32 0
@.str.1 = [272 x i8] c"HTTP/1.1 403 Forbidden\0AContent-Length: 185\0AConnection: close\0AContent-Type: text/html\0A\0A<html><head>\0A<title>403 Forbidden</title>\0A</head><body>\0A<h1>Forbidden</h1>\0AThe requested URL, file type or operation is not allowed on this simple static file webserver.\0A</body></html>\0A\00"
@.str.2 = [17 x i8] c"FORBIDDEN: %s:%s\00"
@.str.3 = [225 x i8] c"HTTP/1.1 404 Not Found\0AContent-Length: 136\0AConnection: close\0AContent-Type: text/html\0A\0A<html><head>\0A<title>404 Not Found</title>\0A</head><body>\0A<h1>Not Found</h1>\0AThe requested URL was not found on this server.\0A</body></html>\0A\00"
@.str.4 = [17 x i8] c"NOT FOUND: %s:%s\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
define void @logger(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [16192 x i8]
%6 = getelementptr inbounds [16192 x i8], [16192 x i8]* %5, i64 0, i64 0
switch i32 %0, label %19 [
i32 42, label %7
i32 403, label %11
i32 404, label %14
]
7: ; preds = %4
%8 = load i32, i32* @errno
%9 = tail call i32 (...) @getpid()
%10 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i32 %8, i32 %9)
br label %17
11: ; preds = %4
%12 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([272 x i8], [272 x i8]* @.str.1, i64 0, i64 0), i32 271)
%13 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
br label %17
14: ; preds = %4
%15 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str.3, i64 0, i64 0), i32 224)
%16 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %1, i8* %2)
br label %17
17: ; preds = %14, %11, %7
%18 = tail call i32 @exit(i32 3)
unreachable
19: ; preds = %4
ret void
}