#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 */
struct mg_connection {
  int dummy;
};
typedef int /*<<< orphan*/ src;
typedef int /*<<< orphan*/ dst;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ mg_conn_addr_to_str(struct mg_connection *, char *, int,
                                       int);
int /*<<< orphan*/ mg_hexdump(void const *, int, char *, int);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char const *, char *);
scalar_t__ time(int /*<<< orphan*/ *);
void mg_hexdump_connection(struct mg_connection *nc, const char *path,
                           const void *buf, int num_bytes, int ev) {
  FILE *fp = NULL;
  char *hexbuf, src[60], dst[60];
  int buf_size = num_bytes * 5 + 100;
  if (strcmp(path, "-") == 0) {
    fp = stdout;
  } else if (strcmp(path, "--") == 0) {
    fp = stderr;
  } else {
    fp = fopen(path, "a");
  }
  if (fp == NULL)
    return;
  mg_conn_addr_to_str(nc, src, sizeof(src), 1 | 2);
  mg_conn_addr_to_str(nc, dst, sizeof(dst), 1 | 2 | 4);
  fprintf(fp, "%lu %p %s %s %s %d\n", (unsigned long)time(NULL), nc, src,
          ev == 3   ? "<-"
          : ev == 4 ? "->"
          : ev == 1 ? "<A"
          : ev == 2 ? "C>"
                    : "XX",
          dst, num_bytes);
  if (num_bytes > 0 && (hexbuf = (char *)malloc(buf_size)) != NULL) {
    mg_hexdump(buf, num_bytes, hexbuf, buf_size);
    fprintf(fp, "%s", hexbuf);
    free(hexbuf);
  }
  if (fp != stdin && fp != stdout)
    fclose(fp);
}


x86 assembly (clang, -O0):
<mg_hexdump_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
imul   $0x5,-0x1c(%rbp),%eax
add    $0x64,%eax
mov    %eax,-0xb4(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f0 <mg_hexdump_connection+0x60>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1236 <mg_hexdump_connection+0xa6>
mov    -0x10(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121d <mg_hexdump_connection+0x8d>
mov    0x2dc7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    1231 <mg_hexdump_connection+0xa1>
mov    -0x10(%rbp),%rdi
lea    0xddb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
jmp    1236 <mg_hexdump_connection+0xa6>
cmpq   $0x0,-0x28(%rbp)
jne    1246 <mg_hexdump_connection+0xb6>
jmp    1406 <mg_hexdump_connection+0x276>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    $0x3c,%edx
mov    $0x3,%ecx
call   1050 <mg_conn_addr_to_str@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
mov    $0x3c,%edx
mov    $0x7,%ecx
call   1050 <mg_conn_addr_to_str@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0xd8(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
mov    %rax,-0xd0(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0xc8(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xc0(%rbp)
cmpl   $0x3,-0x20(%rbp)
jne    12c5 <mg_hexdump_connection+0x135>
lea    0xd60(%rip),%rax
mov    %rax,-0xe0(%rbp)
jmp    133a <mg_hexdump_connection+0x1aa>
cmpl   $0x4,-0x20(%rbp)
jne    12e2 <mg_hexdump_connection+0x152>
lea    0xd46(%rip),%rax
mov    %rax,-0xe8(%rbp)
jmp    132c <mg_hexdump_connection+0x19c>
cmpl   $0x1,-0x20(%rbp)
jne    12ff <mg_hexdump_connection+0x16f>
lea    0xd2c(%rip),%rax
mov    %rax,-0xf0(%rbp)
jmp    131e <mg_hexdump_connection+0x18e>
mov    -0x20(%rbp),%edx
lea    0xd1c(%rip),%rax
lea    0xd12(%rip),%rcx
cmp    $0x2,%edx
cmove  %rcx,%rax
mov    %rax,-0xf0(%rbp)
mov    -0xf0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xc0(%rbp),%r8
mov    -0xc8(%rbp),%rcx
mov    -0xd0(%rbp),%rdx
mov    -0xd8(%rbp),%rdi
mov    -0xe0(%rbp),%r9
lea    -0xb0(%rbp),%r10
mov    -0x1c(%rbp),%eax
lea    0xc97(%rip),%rsi
mov    %r10,(%rsp)
mov    %eax,0x8(%rsp)
mov    $0x0,%al
call   1070 <fprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    13d5 <mg_hexdump_connection+0x245>
mov    -0xb4(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     13d5 <mg_hexdump_connection+0x245>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0xb4(%rbp),%ecx
call   10a0 <mg_hexdump@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xc63(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    0x2c08(%rip),%rcx
cmp    (%rcx),%rax
je     1406 <mg_hexdump_connection+0x276>
mov    -0x28(%rbp),%rax
mov    0x2bdc(%rip),%rcx
cmp    (%rcx),%rax
je     1406 <mg_hexdump_connection+0x276>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mg_hexdump_connection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r8d,%ebp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1204 <mg_hexdump_connection+0x64>
lea    0xe25(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     120d <mg_hexdump_connection+0x6d>
lea    0xe14(%rip),%rsi
mov    %rbx,%rdi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
jne    1220 <mg_hexdump_connection+0x80>
jmp    1318 <mg_hexdump_connection+0x178>
mov    0x2dc5(%rip),%rax
jmp    1214 <mg_hexdump_connection+0x74>
mov    0x2dc4(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
je     1318 <mg_hexdump_connection+0x178>
mov    %rsp,%rsi
mov    %r12,%rdi
mov    $0x3c,%edx
mov    $0x3,%ecx
call   1060 <mg_conn_addr_to_str@plt>
lea    0x40(%rsp),%r13
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x3c,%edx
mov    $0x7,%ecx
call   1060 <mg_conn_addr_to_str@plt>
xor    %edi,%edi
call   1090 <time@plt>
cmp    $0x1,%ebp
je     126e <mg_hexdump_connection+0xce>
cmp    $0x3,%ebp
je     1277 <mg_hexdump_connection+0xd7>
cmp    $0x4,%ebp
jne    1280 <mg_hexdump_connection+0xe0>
lea    0xdb0(%rip),%r9
jmp    1295 <mg_hexdump_connection+0xf5>
lea    0xdaa(%rip),%r9
jmp    1295 <mg_hexdump_connection+0xf5>
lea    0xd9b(%rip),%r9
jmp    1295 <mg_hexdump_connection+0xf5>
cmp    $0x2,%ebp
lea    0xd98(%rip),%rcx
lea    0xd94(%rip),%r9
cmove  %rcx,%r9
lea    0xd69(%rip),%rsi
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %rax,%rdx
mov    %r12,%rcx
xor    %eax,%eax
push   %r15
push   %r13
call   1080 <fprintf@plt>
add    $0x10,%rsp
test   %r15d,%r15d
jle    12f8 <mg_hexdump_connection+0x158>
lea    (%r15,%r15,4),%r12d
add    $0x64,%r12d
mov    %r12d,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12f8 <mg_hexdump_connection+0x158>
mov    %rax,%rbp
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rax,%rdx
mov    %r12d,%ecx
call   10b0 <mg_hexdump@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    0x2ce9(%rip),%rax
cmp    (%rax),%rbx
je     1318 <mg_hexdump_connection+0x178>
mov    0x2cc5(%rip),%rax
cmp    (%rax),%rbx
je     1318 <mg_hexdump_connection+0x178>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mg_connection = type { i32 }
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"--\00"
@stderr = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"%lu %p %s %s %s %d\0A\00"
@.str.4 = [3 x i8] c"<-\00"
@.str.5 = [3 x i8] c"->\00"
@.str.6 = [3 x i8] c"<A\00"
@.str.7 = [3 x i8] c"C>\00"
@.str.8 = [3 x i8] c"XX\00"
@.str.9 = [3 x i8] c"%s\00"
@stdin = global i32* null
define void @mg_hexdump_connection(%struct.mg_connection* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca %struct.mg_connection*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca [60 x i8]
%14 = alloca [60 x i8]
%15 = alloca i32
store %struct.mg_connection* %0, %struct.mg_connection** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
store i32* null, i32** %11
%16 = load i32, i32* %9
%17 = mul nsw i32 %16, 5
%18 = add nsw i32 %17, 100
store i32 %18, i32* %15
%19 = load i8*, i8** %7
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %5
%23 = load i32*, i32** @stdout
store i32* %23, i32** %11
br label %34
24: ; preds = %5
%25 = load i8*, i8** %7
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = load i32*, i32** @stderr
store i32* %29, i32** %11
br label %33
30: ; preds = %24
%31 = load i8*, i8** %7
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %11
br label %33
33: ; preds = %30, %28
br label %34
34: ; preds = %33, %22
%35 = load i32*, i32** %11
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %38
37: ; preds = %34
br label %103
38: ; preds = %34
%39 = load %struct.mg_connection*, %struct.mg_connection** %6
%40 = getelementptr inbounds [60 x i8], [60 x i8]* %13, i64 0, i64 0
%41 = call i32 @mg_conn_addr_to_str(%struct.mg_connection* %39, i8* %40, i32 60, i32 3)
%42 = load %struct.mg_connection*, %struct.mg_connection** %6
%43 = getelementptr inbounds [60 x i8], [60 x i8]* %14, i64 0, i64 0
%44 = call i32 @mg_conn_addr_to_str(%struct.mg_connection* %42, i8* %43, i32 60, i32 7)
%45 = load i32*, i32** %11
%46 = call i64 @time(i32* null)
%47 = load %struct.mg_connection*, %struct.mg_connection** %6
%48 = getelementptr inbounds [60 x i8], [60 x i8]* %13, i64 0, i64 0
%49 = load i32, i32* %10
%50 = icmp eq i32 %49, 3
br i1 %50, label %51, label %52
51: ; preds = %38
br label %69
52: ; preds = %38
%53 = load i32, i32* %10
%54 = icmp eq i32 %53, 4
br i1 %54, label %55, label %56
55: ; preds = %52
br label %67
56: ; preds = %52
%57 = load i32, i32* %10
%58 = icmp eq i32 %57, 1
br i1 %58, label %59, label %60
59: ; preds = %56
br label %65
60: ; preds = %56
%61 = load i32, i32* %10
%62 = icmp eq i32 %61, 2
%63 = zext i1 %62 to i64
%64 = select i1 %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
br label %65
65: ; preds = %60, %59
%66 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %59 ], [ %64, %60 ]
br label %67
67: ; preds = %65, %55
%68 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %55 ], [ %66, %65 ]
br label %69
69: ; preds = %67, %51
%70 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %51 ], [ %68, %67 ]
%71 = getelementptr inbounds [60 x i8], [60 x i8]* %14, i64 0, i64 0
%72 = load i32, i32* %9
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %46, %struct.mg_connection* %47, i8* %48, i8* %70, i8* %71, i32 %72)
%74 = load i32, i32* %9
%75 = icmp sgt i32 %74, 0
br i1 %75, label %76, label %92
76: ; preds = %69
%77 = load i32, i32* %15
%78 = call i64 @malloc(i32 %77)
%79 = inttoptr i64 %78 to i8*
store i8* %79, i8** %12
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %92
81: ; preds = %76
%82 = load i8*, i8** %8
%83 = load i32, i32* %9
%84 = load i8*, i8** %12
%85 = load i32, i32* %15
%86 = call i32 @mg_hexdump(i8* %82, i32 %83, i8* %84, i32 %85)
%87 = load i32*, i32** %11
%88 = load i8*, i8** %12
%89 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %12
%91 = call i32 @free(i8* %90)
br label %92
92: ; preds = %81, %76, %69
%93 = load i32*, i32** %11
%94 = load i32*, i32** @stdin
%95 = icmp ne i32* %93, %94
br i1 %95, label %96, label %103
96: ; preds = %92
%97 = load i32*, i32** %11
%98 = load i32*, i32** @stdout
%99 = icmp ne i32* %97, %98
br i1 %99, label %100, label %103
100: ; preds = %96
%101 = load i32*, i32** %11
%102 = call i32 @fclose(i32* %101)
br label %103
103: ; preds = %37, %100, %96, %92
ret void
}

LLVM IR (-O2):
%struct.mg_connection = type { i32 }
@.str = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.1 = [3 x i8] c"--\00"
@stderr = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [20 x i8] c"%lu %p %s %s %s %d\0A\00"
@.str.4 = [3 x i8] c"<-\00"
@.str.5 = [3 x i8] c"->\00"
@.str.6 = [3 x i8] c"<A\00"
@.str.7 = [3 x i8] c"C>\00"
@.str.8 = [3 x i8] c"XX\00"
@stdin = global i32* null
define void @mg_hexdump_connection(%struct.mg_connection* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca [60 x i8]
%7 = alloca [60 x i8]
%8 = getelementptr inbounds [60 x i8], [60 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%10 = mul nsw i32 %3, 5
%11 = add nsw i32 %10, 100
%12 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %5
%15 = load i32*, i32** @stdout
br label %23
16: ; preds = %5
%17 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = load i32*, i32** @stderr
br label %23
21: ; preds = %16
%22 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %19, %21, %14
%24 = phi i32* [ %15, %14 ], [ %20, %19 ], [ %22, %21 ]
%25 = icmp eq i32* %24, null
br i1 %25, label %55, label %26
26: ; preds = %23
%27 = call i32 @mg_conn_addr_to_str(%struct.mg_connection* %0, i8* %8, i32 60, i32 3)
%28 = call i32 @mg_conn_addr_to_str(%struct.mg_connection* %0, i8* %9, i32 60, i32 7)
%29 = call i64 @time(i32* null)
switch i32 %4, label %30 [
i32 3, label %35
i32 4, label %33
i32 1, label %34
]
30: ; preds = %26
%31 = icmp eq i32 %4, 2
%32 = select i1 %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
br label %35
33: ; preds = %26
br label %35
34: ; preds = %26
br label %35
35: ; preds = %26, %34, %33, %30
%36 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %26 ], [ %32, %30 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %33 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %34 ]
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i64 %29, %struct.mg_connection* %0, i8* %8, i8* %36, i8* %9, i32 %3)
%38 = icmp sgt i32 %3, 0
br i1 %38, label %39, label %47
39: ; preds = %35
%40 = call i64 @malloc(i32 %11)
%41 = inttoptr i64 %40 to i8*
%42 = icmp eq i64 %40, 0
br i1 %42, label %47, label %43
43: ; preds = %39
%44 = call i32 @mg_hexdump(i8* %2, i32 %3, i8* %41, i32 %11)
%45 = call i32 @fputs(i8* %41, i32* %24)
%46 = call i32 @free(i8* %41)
br label %47
47: ; preds = %43, %39, %35
%48 = load i32*, i32** @stdin
%49 = icmp eq i32* %24, %48
%50 = load i32*, i32** @stdout
%51 = icmp eq i32* %24, %50
%52 = select i1 %49, i1 true, i1 %51
br i1 %52, label %55, label %53
53: ; preds = %47
%54 = call i32 @fclose(i32* %24)
br label %55
55: ; preds = %47, %53, %23
ret void
}