#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 tm {
  int tm_hour;
  int tm_min;
  int tm_sec;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int, int,
                           char const *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
void printLogHeader(int level, const char *tag, FILE *outfile) {
  struct timeval current_time;
  struct tm *t;
  int msecs;
  gettimeofday(&current_time, NULL);
  t = gmtime(&current_time.tv_sec);
  msecs = current_time.tv_usec / 1000;
  switch (level) {
  case 10:
    fprintf(outfile, "%02d:%02d:%02d,%03d DEBUG %s: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs, tag);
    break;
  case 20:
    fprintf(outfile, "%02d:%02d:%02d,%03d INFO %s: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs, tag);
    break;
  case 30:
    fprintf(outfile, "%02d:%02d:%02d,%03d WARNING %s: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs, tag);
    break;
  case 40:
    fprintf(outfile, "%02d:%02d:%02d,%03d ERROR %s: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs, tag);
    break;
  case 50:
    fprintf(outfile, "%02d:%02d:%02d,%03d CRITICAL %s: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs, tag);
    break;
  }
}


x86 assembly (clang, -O0):
<printLogHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   1030 <gettimeofday@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x28(%rbp)
movslq -0x20(%rbp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x28,%eax
ja     12aa <printLogHeader+0x17a>
mov    -0x38(%rbp),%rax
lea    0xe68(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xedb(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
jmp    12aa <printLogHeader+0x17a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xec4(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
jmp    12aa <printLogHeader+0x17a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xeac(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
jmp    12aa <printLogHeader+0x17a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xe97(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
jmp    12aa <printLogHeader+0x17a>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x10(%rbp),%rax
lea    0xe80(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLogHeader>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
call   1050 <gmtime@plt>
add    $0xfffffff6,%ebx
cmp    $0x28,%ebx
ja     11c7 <printLogHeader+0x97>
movslq 0x8(%rsp),%rcx
lea    0xf39(%rip),%rsi
lea    0xe8e(%rip),%rdx
movslq (%rdx,%rbx,4),%rdi
add    %rdx,%rdi
jmp    *%rdi
lea    0xf41(%rip),%rsi
jmp    119d <printLogHeader+0x6d>
lea    0xf56(%rip),%rsi
jmp    119d <printLogHeader+0x6d>
lea    0xf6e(%rip),%rsi
jmp    119d <printLogHeader+0x6d>
lea    0xf84(%rip),%rsi
imul   $0x10624dd3,%rcx,%r9
mov    %r9,%rcx
shr    $0x3f,%rcx
sar    $0x26,%r9
add    %ecx,%r9d
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
mov    %r15,(%rsp)
mov    %r14,%rdi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [31 x i8] c"%02d:%02d:%02d,%03d DEBUG %s: \00"
@.str.1 = [30 x i8] c"%02d:%02d:%02d,%03d INFO %s: \00"
@.str.2 = [33 x i8] c"%02d:%02d:%02d,%03d WARNING %s: \00"
@.str.3 = [31 x i8] c"%02d:%02d:%02d,%03d ERROR %s: \00"
@.str.4 = [34 x i8] c"%02d:%02d:%02d,%03d CRITICAL %s: \00"
define void @printLogHeader(i32 %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.timeval
%8 = alloca %struct.tm*
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%10 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%12 = call %struct.tm* @gmtime(i32* %11)
store %struct.tm* %12, %struct.tm** %8
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%14 = load i32, i32* %13
%15 = sdiv i32 %14, 1000
store i32 %15, i32* %9
%16 = load i32, i32* %4
switch i32 %16, label %87 [
i32 10, label %17
i32 20, label %31
i32 30, label %45
i32 40, label %59
i32 50, label %73
]
17: ; preds = %3
%18 = load i32*, i32** %6
%19 = load %struct.tm*, %struct.tm** %8
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load %struct.tm*, %struct.tm** %8
%23 = getelementptr inbounds %struct.tm, %struct.tm* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load %struct.tm*, %struct.tm** %8
%26 = getelementptr inbounds %struct.tm, %struct.tm* %25, i32 0, i32 2
%27 = load i32, i32* %26
%28 = load i32, i32* %9
%29 = load i8*, i8** %5
%30 = call i32 @fprintf(i32* %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %24, i32 %27, i32 %28, i8* %29)
br label %87
31: ; preds = %3
%32 = load i32*, i32** %6
%33 = load %struct.tm*, %struct.tm** %8
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load %struct.tm*, %struct.tm** %8
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = load %struct.tm*, %struct.tm** %8
%40 = getelementptr inbounds %struct.tm, %struct.tm* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = load i32, i32* %9
%43 = load i8*, i8** %5
%44 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %38, i32 %41, i32 %42, i8* %43)
br label %87
45: ; preds = %3
%46 = load i32*, i32** %6
%47 = load %struct.tm*, %struct.tm** %8
%48 = getelementptr inbounds %struct.tm, %struct.tm* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = load %struct.tm*, %struct.tm** %8
%51 = getelementptr inbounds %struct.tm, %struct.tm* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load %struct.tm*, %struct.tm** %8
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 2
%55 = load i32, i32* %54
%56 = load i32, i32* %9
%57 = load i8*, i8** %5
%58 = call i32 @fprintf(i32* %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %52, i32 %55, i32 %56, i8* %57)
br label %87
59: ; preds = %3
%60 = load i32*, i32** %6
%61 = load %struct.tm*, %struct.tm** %8
%62 = getelementptr inbounds %struct.tm, %struct.tm* %61, i32 0, i32 0
%63 = load i32, i32* %62
%64 = load %struct.tm*, %struct.tm** %8
%65 = getelementptr inbounds %struct.tm, %struct.tm* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = load %struct.tm*, %struct.tm** %8
%68 = getelementptr inbounds %struct.tm, %struct.tm* %67, i32 0, i32 2
%69 = load i32, i32* %68
%70 = load i32, i32* %9
%71 = load i8*, i8** %5
%72 = call i32 @fprintf(i32* %60, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %63, i32 %66, i32 %69, i32 %70, i8* %71)
br label %87
73: ; preds = %3
%74 = load i32*, i32** %6
%75 = load %struct.tm*, %struct.tm** %8
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 0
%77 = load i32, i32* %76
%78 = load %struct.tm*, %struct.tm** %8
%79 = getelementptr inbounds %struct.tm, %struct.tm* %78, i32 0, i32 1
%80 = load i32, i32* %79
%81 = load %struct.tm*, %struct.tm** %8
%82 = getelementptr inbounds %struct.tm, %struct.tm* %81, i32 0, i32 2
%83 = load i32, i32* %82
%84 = load i32, i32* %9
%85 = load i8*, i8** %5
%86 = call i32 @fprintf(i32* %74, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %77, i32 %80, i32 %83, i32 %84, i8* %85)
br label %87
87: ; preds = %3, %73, %59, %45, %31, %17
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32 }
@.str = [31 x i8] c"%02d:%02d:%02d,%03d DEBUG %s: \00"
@.str.1 = [30 x i8] c"%02d:%02d:%02d,%03d INFO %s: \00"
@.str.2 = [33 x i8] c"%02d:%02d:%02d,%03d WARNING %s: \00"
@.str.3 = [31 x i8] c"%02d:%02d:%02d,%03d ERROR %s: \00"
@.str.4 = [34 x i8] c"%02d:%02d:%02d,%03d CRITICAL %s: \00"
define void @printLogHeader(i32 %0, i8* %1, i32* nocapture %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%8 = call %struct.tm* @gmtime(i32* %7)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000
switch i32 %0, label %25 [
i32 10, label %16
i32 20, label %12
i32 30, label %13
i32 40, label %14
i32 50, label %15
]
12: ; preds = %3
br label %16
13: ; preds = %3
br label %16
14: ; preds = %3
br label %16
15: ; preds = %3
br label %16
16: ; preds = %3, %12, %13, %14, %15
%17 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), %15 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %14 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %3 ]
%18 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 0
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.tm, %struct.tm* %8, i64 0, i32 2
%23 = load i32, i32* %22
%24 = call i32 @fprintf(i32* %2, i8* %17, i32 %19, i32 %21, i32 %23, i32 %11, i8* %1)
br label %25
25: ; preds = %16, %3
ret void
}