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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, int);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void printLogHeader(int level, FILE *outfile) {
  time_t current_time = time(NULL);
  struct tm *t = gmtime(&current_time);
  switch (level) {
  case 10:
    fprintf(outfile, "%02d:%02d:%02d DEBUG   : ", t->tm_hour, t->tm_min,
            t->tm_sec);
    break;
  case 20:
    fprintf(outfile, "%02d:%02d:%02d INFO    : ", t->tm_hour, t->tm_min,
            t->tm_sec);
    break;
  case 30:
    fprintf(outfile, "%02d:%02d:%02d WARNING : ", t->tm_hour, t->tm_min,
            t->tm_sec);
    break;
  case 40:
    fprintf(outfile, "%02d:%02d:%02d ERROR   : ", t->tm_hour, t->tm_min,
            t->tm_sec);
    break;
  case 50:
    fprintf(outfile, "%02d:%02d:%02d CRITICAL: ", t->tm_hour, t->tm_min,
            t->tm_sec);
    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,%edi
call   1040 <time@plt>
mov    %eax,-0x14(%rbp)
lea    -0x14(%rbp),%rdi
call   1050 <gmtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfffffff6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x28,%eax
ja     124e <printLogHeader+0x11e>
mov    -0x28(%rbp),%rax
lea    0xe88(%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
lea    0xf03(%rip),%rsi
call   1030 <fprintf@plt>
jmp    124e <printLogHeader+0x11e>
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
lea    0xef3(%rip),%rsi
call   1030 <fprintf@plt>
jmp    124e <printLogHeader+0x11e>
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
lea    0xee3(%rip),%rsi
call   1030 <fprintf@plt>
jmp    124e <printLogHeader+0x11e>
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
lea    0xed3(%rip),%rsi
call   1030 <fprintf@plt>
jmp    124e <printLogHeader+0x11e>
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
lea    0xec3(%rip),%rsi
call   1030 <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
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1050 <gmtime@plt>
add    $0xfffffff6,%ebx
cmp    $0x28,%ebx
ja     11a0 <printLogHeader+0x70>
lea    0xf47(%rip),%rsi
lea    0xe9c(%rip),%rcx
movslq (%rcx,%rbx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xf4a(%rip),%rsi
jmp    118f <printLogHeader+0x5f>
lea    0xf5b(%rip),%rsi
jmp    118f <printLogHeader+0x5f>
lea    0xf6c(%rip),%rsi
jmp    118f <printLogHeader+0x5f>
lea    0xf7d(%rip),%rsi
mov    (%rax),%edx
mov    0x4(%rax),%ecx
mov    0x8(%rax),%r8d
mov    %r14,%rdi
call   1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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