#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 /*<<< orphan*/ nweb_write(int, char *, int);
int open(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, ...);
int strlen(char *);
void logger(int type, char *s1, char *s2, int socket_fd) {
  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)nweb_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)nweb_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:
    (void)sprintf(logbuffer, " INFO: %s:%s:%d", s1, s2, socket_fd);
    break;
  }
  if ((fd = open("nweb.log", O_CREAT | O_WRONLY | O_APPEND, 0644)) >= 0) {
    (void)nweb_write(fd, logbuffer, strlen(logbuffer));
    (void)nweb_write(fd, "\n", 1);
    (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)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3f64(%rbp)
sub    $0x2a,%eax
je     11e0 <logger+0x70>
jmp    11a0 <logger+0x30>
mov    -0x3f64(%rbp),%eax
sub    $0x2c,%eax
je     12b8 <logger+0x148>
jmp    11b4 <logger+0x44>
mov    -0x3f64(%rbp),%eax
sub    $0x193,%eax
je     124c <logger+0xdc>
jmp    11ca <logger+0x5a>
mov    -0x3f64(%rbp),%eax
sub    $0x194,%eax
je     1282 <logger+0x112>
jmp    12d9 <logger+0x169>
lea    -0x3f60(%rbp),%rax
mov    %rax,-0x3f80(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x3f78(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x3f70(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3f68(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x3f80(%rbp),%rdi
mov    -0x3f78(%rbp),%rdx
mov    -0x3f70(%rbp),%rcx
mov    -0x3f68(%rbp),%r8d
mov    %eax,%r9d
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    12d9 <logger+0x169>
mov    -0x1c(%rbp),%edi
lea    0xdcf(%rip),%rsi
mov    $0x10f,%edx
call   1060 <nweb_write@plt>
lea    -0x3f60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    12d9 <logger+0x169>
mov    -0x1c(%rbp),%edi
lea    0xeba(%rip),%rsi
mov    $0xe0,%edx
call   1060 <nweb_write@plt>
lea    -0x3f60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xf7b(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    12d9 <logger+0x169>
lea    -0x3f60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xf66(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%esi
mov    0x2cdf(%rip),%rax
or     (%rax),%esi
mov    0x2cce(%rip),%rax
or     (%rax),%esi
lea    0xf4d(%rip),%rdi
mov    $0x1a4,%edx
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jl     1364 <logger+0x1f4>
mov    -0x20(%rbp),%eax
mov    %eax,-0x3f8c(%rbp)
lea    -0x3f60(%rbp),%rax
mov    %rax,-0x3f88(%rbp)
lea    -0x3f60(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3f8c(%rbp),%edi
mov    -0x3f88(%rbp),%rsi
mov    %eax,%edx
call   1060 <nweb_write@plt>
mov    -0x20(%rbp),%edi
lea    0xed3(%rip),%rsi
mov    $0x1,%edx
call   1060 <nweb_write@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
cmpl   $0x2a,-0x4(%rbp)
je     1388 <logger+0x218>
cmpl   $0x194,-0x4(%rbp)
je     1388 <logger+0x218>
cmpl   $0x193,-0x4(%rbp)
jne    1392 <logger+0x222>
mov    $0x3,%edi
call   1090 <exit@plt>
add    $0x3f90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logger>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3f48,%rsp
mov    %ecx,%r8d
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
cmp    $0x192,%edi
jg     11ba <logger+0x4a>
cmp    $0x2a,%ebx
je     11e7 <logger+0x77>
cmp    $0x2c,%ebx
jne    1241 <logger+0xd1>
lea    0x1093(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    1241 <logger+0xd1>
cmp    $0x193,%ebx
je     1216 <logger+0xa6>
cmp    $0x194,%ebx
jne    1241 <logger+0xd1>
lea    0xf75(%rip),%rsi
mov    %r8d,%edi
mov    $0xe0,%edx
call   1060 <nweb_write@plt>
lea    0x1042(%rip),%rsi
jmp    1231 <logger+0xc1>
mov    0x2dea(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe02(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %ebp,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    1241 <logger+0xd1>
lea    0xe08(%rip),%rsi
mov    %r8d,%edi
mov    $0x10f,%edx
call   1060 <nweb_write@plt>
lea    0xf04(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x2db0(%rip),%rax
mov    0x2d79(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d66(%rip),%rax
or     (%rax),%esi
lea    0xfe5(%rip),%rdi
mov    $0x1a4,%edx
call   1070 <open@plt>
test   %eax,%eax
js     12a4 <logger+0x134>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1060 <nweb_write@plt>
lea    0xf94(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1060 <nweb_write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    -0x193(%rbx),%eax
cmp    $0x2,%eax
jb     12c2 <logger+0x152>
cmp    $0x2a,%ebx
je     12c2 <logger+0x152>
add    $0x3f48,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x3,%edi
call   1090 <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 = [16 x i8] c" INFO: %s:%s:%d\00"
@.str.6 = [9 x i8] c"nweb.log\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
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 [16192 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %5
switch i32 %11, label %39 [
i32 42, label %12
i32 403, label %19
i32 404, label %26
i32 44, label %33
]
12: ; preds = %4
%13 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%14 = load i8*, i8** %6
%15 = load i8*, i8** %7
%16 = load i32, i32* @errno
%17 = call i32 (...) @getpid()
%18 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %15, i32 %16, i32 %17)
br label %39
19: ; preds = %4
%20 = load i32, i32* %8
%21 = call i32 @nweb_write(i32 %20, i8* getelementptr inbounds ([272 x i8], [272 x i8]* @.str.1, i64 0, i64 0), i32 271)
%22 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24)
br label %39
26: ; preds = %4
%27 = load i32, i32* %8
%28 = call i32 @nweb_write(i32 %27, i8* getelementptr inbounds ([225 x i8], [225 x i8]* @.str.3, i64 0, i64 0), i32 224)
%29 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* %31)
br label %39
33: ; preds = %4
%34 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = load i32, i32* %8
%38 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %34, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %35, i8* %36, i32 %37)
br label %39
39: ; preds = %4, %33, %26, %19, %12
%40 = load i32, i32* @O_CREAT
%41 = load i32, i32* @O_WRONLY
%42 = or i32 %40, %41
%43 = load i32, i32* @O_APPEND
%44 = or i32 %42, %43
%45 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %44, i32 420)
store i32 %45, i32* %9
%46 = icmp sge i32 %45, 0
br i1 %46, label %47, label %57
47: ; preds = %39
%48 = load i32, i32* %9
%49 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%50 = getelementptr inbounds [16192 x i8], [16192 x i8]* %10, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = call i32 @nweb_write(i32 %48, i8* %49, i32 %51)
%53 = load i32, i32* %9
%54 = call i32 @nweb_write(i32 %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1)
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
br label %57
57: ; preds = %47, %39
%58 = load i32, i32* %5
%59 = icmp eq i32 %58, 42
br i1 %59, label %66, label %60
60: ; preds = %57
%61 = load i32, i32* %5
%62 = icmp eq i32 %61, 404
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = load i32, i32* %5
%65 = icmp eq i32 %64, 403
br i1 %65, label %66, label %68
66: ; preds = %63, %60, %57
%67 = call i32 @exit(i32 3)
unreachable
68: ; preds = %63
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"
@.str.5 = [16 x i8] c" INFO: %s:%s:%d\00"
@.str.6 = [9 x i8] c"nweb.log\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.7 = [2 x i8] c"\0A\00"
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
i32 44, label %17
]
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 %19
11: ; preds = %4
%12 = tail call i32 @nweb_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 %19
14: ; preds = %4
%15 = tail call i32 @nweb_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 %19
17: ; preds = %4
%18 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %2, i32 %3)
br label %19
19: ; preds = %4, %17, %14, %11, %7
%20 = load i32, i32* @O_CREAT
%21 = load i32, i32* @O_WRONLY
%22 = or i32 %21, %20
%23 = load i32, i32* @O_APPEND
%24 = or i32 %22, %23
%25 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %24, i32 420)
%26 = icmp sgt i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %19
%28 = call i32 @strlen(i8* %6)
%29 = call i32 @nweb_write(i32 %25, i8* %6, i32 %28)
%30 = call i32 @nweb_write(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 1)
%31 = call i32 @close(i32 %25)
br label %32
32: ; preds = %27, %19
switch i32 %0, label %35 [
i32 404, label %33
i32 403, label %33
i32 42, label %33
]
33: ; preds = %32, %32, %32
%34 = call i32 @exit(i32 3)
unreachable
35: ; preds = %32
ret void
}