#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);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
void printLogHeader(int level, 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   : ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs);
    break;
  case 20:
    fprintf(outfile, "%02d:%02d:%02d,%03d INFO    : ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs);
    break;
  case 30:
    fprintf(outfile, "%02d:%02d:%02d,%03d WARNING : ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs);
    break;
  case 40:
    fprintf(outfile, "%02d:%02d:%02d,%03d ERROR   : ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs);
    break;
  case 50:
    fprintf(outfile, "%02d:%02d:%02d,%03d CRITICAL: ", t->tm_hour, t->tm_min,
            t->tm_sec, msecs);
    break;
  }
}


x86 assembly (clang, -O0):
<printLogHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdi
call   1030 <gettimeofday@plt>
lea    -0x14(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x20(%rbp)
movslq -0x18(%rbp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x28,%eax
ja     127e <printLogHeader+0x14e>
mov    -0x30(%rbp),%rax
lea    0xe6c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x24(%rbp),%r9d
lea    0xee3(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127e <printLogHeader+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x24(%rbp),%r9d
lea    0xed4(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127e <printLogHeader+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x24(%rbp),%r9d
lea    0xec5(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127e <printLogHeader+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x24(%rbp),%r9d
lea    0xeb6(%rip),%rsi
call   1040 <fprintf@plt>
jmp    127e <printLogHeader+0x14e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x24(%rbp),%r9d
lea    0xea7(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLogHeader>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x4(%rsp),%rdi
call   1050 <gmtime@plt>
add    $0xfffffff6,%ebx
cmp    $0x28,%ebx
ja     11b8 <printLogHeader+0x88>
movslq (%rsp),%rcx
lea    0xf44(%rip),%rsi
lea    0xe99(%rip),%rdx
movslq (%rdx,%rbx,4),%rdi
add    %rdx,%rdi
jmp    *%rdi
lea    0xf4c(%rip),%rsi
jmp    1192 <printLogHeader+0x62>
lea    0xf62(%rip),%rsi
jmp    1192 <printLogHeader+0x62>
lea    0xf78(%rip),%rsi
jmp    1192 <printLogHeader+0x62>
lea    0xf8e(%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    %r14,%rdi
call   1040 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
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 : \00"
@.str.1 = [31 x i8] c"%02d:%02d:%02d,%03d INFO : \00"
@.str.2 = [31 x i8] c"%02d:%02d:%02d,%03d WARNING : \00"
@.str.3 = [31 x i8] c"%02d:%02d:%02d,%03d ERROR : \00"
@.str.4 = [31 x i8] c"%02d:%02d:%02d,%03d CRITICAL: \00"
define void @printLogHeader(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca %struct.timeval
%6 = alloca %struct.tm*
%7 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
%8 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%10 = call %struct.tm* @gmtime(i32* %9)
store %struct.tm* %10, %struct.tm** %6
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
store i32 %13, i32* %7
%14 = load i32, i32* %3
switch i32 %14, label %80 [
i32 10, label %15
i32 20, label %28
i32 30, label %41
i32 40, label %54
i32 50, label %67
]
15: ; preds = %2
%16 = load i32*, i32** %4
%17 = load %struct.tm*, %struct.tm** %6
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = load %struct.tm*, %struct.tm** %6
%21 = getelementptr inbounds %struct.tm, %struct.tm* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = load %struct.tm*, %struct.tm** %6
%24 = getelementptr inbounds %struct.tm, %struct.tm* %23, i32 0, i32 2
%25 = load i32, i32* %24
%26 = load i32, i32* %7
%27 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %22, i32 %25, i32 %26)
br label %80
28: ; preds = %2
%29 = load i32*, i32** %4
%30 = load %struct.tm*, %struct.tm** %6
%31 = getelementptr inbounds %struct.tm, %struct.tm* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load %struct.tm*, %struct.tm** %6
%34 = getelementptr inbounds %struct.tm, %struct.tm* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load %struct.tm*, %struct.tm** %6
%37 = getelementptr inbounds %struct.tm, %struct.tm* %36, i32 0, i32 2
%38 = load i32, i32* %37
%39 = load i32, i32* %7
%40 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %35, i32 %38, i32 %39)
br label %80
41: ; preds = %2
%42 = load i32*, i32** %4
%43 = load %struct.tm*, %struct.tm** %6
%44 = getelementptr inbounds %struct.tm, %struct.tm* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load %struct.tm*, %struct.tm** %6
%47 = getelementptr inbounds %struct.tm, %struct.tm* %46, i32 0, i32 1
%48 = load i32, i32* %47
%49 = load %struct.tm*, %struct.tm** %6
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = load i32, i32* %7
%53 = call i32 @fprintf(i32* %42, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %48, i32 %51, i32 %52)
br label %80
54: ; preds = %2
%55 = load i32*, i32** %4
%56 = load %struct.tm*, %struct.tm** %6
%57 = getelementptr inbounds %struct.tm, %struct.tm* %56, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load %struct.tm*, %struct.tm** %6
%60 = getelementptr inbounds %struct.tm, %struct.tm* %59, i32 0, i32 1
%61 = load i32, i32* %60
%62 = load %struct.tm*, %struct.tm** %6
%63 = getelementptr inbounds %struct.tm, %struct.tm* %62, i32 0, i32 2
%64 = load i32, i32* %63
%65 = load i32, i32* %7
%66 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %58, i32 %61, i32 %64, i32 %65)
br label %80
67: ; preds = %2
%68 = load i32*, i32** %4
%69 = load %struct.tm*, %struct.tm** %6
%70 = getelementptr inbounds %struct.tm, %struct.tm* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load %struct.tm*, %struct.tm** %6
%73 = getelementptr inbounds %struct.tm, %struct.tm* %72, i32 0, i32 1
%74 = load i32, i32* %73
%75 = load %struct.tm*, %struct.tm** %6
%76 = getelementptr inbounds %struct.tm, %struct.tm* %75, i32 0, i32 2
%77 = load i32, i32* %76
%78 = load i32, i32* %7
%79 = call i32 @fprintf(i32* %68, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %71, i32 %74, i32 %77, i32 %78)
br label %80
80: ; preds = %2, %67, %54, %41, %28, %15
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 : \00"
@.str.1 = [31 x i8] c"%02d:%02d:%02d,%03d INFO : \00"
@.str.2 = [31 x i8] c"%02d:%02d:%02d,%03d WARNING : \00"
@.str.3 = [31 x i8] c"%02d:%02d:%02d,%03d ERROR : \00"
@.str.4 = [31 x i8] c"%02d:%02d:%02d,%03d CRITICAL: \00"
define void @printLogHeader(i32 %0, i32* nocapture %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%7 = call %struct.tm* @gmtime(i32* %6)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sdiv i32 %9, 1000
switch i32 %0, label %24 [
i32 10, label %15
i32 20, label %11
i32 30, label %12
i32 40, label %13
i32 50, label %14
]
11: ; preds = %2
br label %15
12: ; preds = %2
br label %15
13: ; preds = %2
br label %15
14: ; preds = %2
br label %15
15: ; preds = %2, %11, %12, %13, %14
%16 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), %14 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %13 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), %12 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %2 ]
%17 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %7, i64 0, i32 2
%22 = load i32, i32* %21
%23 = call i32 @fprintf(i32* %1, i8* %16, i32 %18, i32 %20, i32 %22, i32 %10)
br label %24
24: ; preds = %15, %2
ret void
}