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

/* Variables and functions */
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int, int, int,
                            ...);
void getheader(char *head, int size, int msec) {
  struct timeval tv;
  struct tm *t_st;
  char host[128];
  char *p;
  (void)gettimeofday(&tv, NULL);
  t_st = localtime(&tv.tv_sec);
  (void)gethostname(host, sizeof(host));
  p = host;
  while (*p != '\0') {
    if (*p == '.') {
      *p = '\0';
      break;
    }
    p++;
  }
  if (msec) {
    snprintf(head, size, "%04d/%02d/%02d %02d:%02d:%02d.%03d %s ",
             t_st->tm_year + 1900, t_st->tm_mon + 1, t_st->tm_mday,
             t_st->tm_hour, t_st->tm_min, t_st->tm_sec, tv.tv_usec / 1000,
             host);
  } else {
    snprintf(head, size, "%04d/%02d/%02d %02d:%02d:%02d %s ",
             t_st->tm_year + 1900, t_st->tm_mon + 1, t_st->tm_mday,
             t_st->tm_hour, t_st->tm_min, t_st->tm_sec, host);
  }
}


x86 assembly (clang, -O0):
<getheader>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    %edx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
lea    -0x28(%rbp),%rdi
add    $0x4,%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1060 <gethostname@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e1 <getheader+0xa1>
mov    -0xb8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11ca <getheader+0x8a>
mov    -0xb8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e1 <getheader+0xa1>
mov    -0xb8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xb8(%rbp)
jmp    1195 <getheader+0x55>
cmpl   $0x0,-0x20(%rbp)
je     126a <getheader+0x12a>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%r14d
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%ebx
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%r11d
mov    -0x28(%rbp),%eax
mov    $0x3e8,%r10d
cltd
idiv   %r10d
mov    %eax,%r10d
lea    -0xb0(%rbp),%rax
lea    0xdb9(%rip),%rdx
mov    %r14d,(%rsp)
mov    %ebx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12cf <getheader+0x18f>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%ecx
add    $0x76c,%ecx
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r9d
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%ebx
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%r11d
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%r10d
lea    -0xb0(%rbp),%rax
lea    0xd71(%rip),%rdx
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<getheader>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
call   1030 <localtime@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <gethostname@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx),%eax
test   %al,%al
je     11a4 <getheader+0x64>
cmp    $0x2e,%al
je     11a1 <getheader+0x61>
add    $0x1,%rbx
jmp    1190 <getheader+0x50>
movb   $0x0,(%rbx)
mov    $0x76c,%ecx
add    0x0(%rbp),%ecx
mov    0x4(%rbp),%r8d
mov    0x8(%rbp),%r9d
add    $0x1,%r8d
mov    0xc(%rbp),%r10d
mov    0x10(%rbp),%r11d
mov    0x14(%rbp),%ebp
test   %r12d,%r12d
je     120c <getheader+0xcc>
movslq 0x8(%rsp),%rax
imul   $0x10624dd3,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
sub    $0x8,%rsp
lea    0x18(%rsp),%r12
lea    0xe0f(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
push   %r12
push   %rbx
push   %rbp
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x30,%rsp
jmp    122f <getheader+0xef>
lea    0x10(%rsp),%rbx
lea    0xe0f(%rip),%rdx
mov    %r15,%rdi
mov    %r14d,%esi
xor    %eax,%eax
push   %rbx
push   %rbp
push   %r11
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [39 x i8] c"%04d/%02d/%02d %02d:%02d:%02d.%03d %s \00"
@.str.1 = [34 x i8] c"%04d/%02d/%02d %02d:%02d:%02d %s \00"
define void @getheader(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.timeval
%5 = alloca [128 x i8]
%6 = bitcast %struct.timeval* %4 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%10 = call %struct.tm* @localtime(i32* %9)
%11 = call i32 @gethostname(i8* %7, i32 128)
br label %12
12: ; preds = %16, %3
%13 = phi i8* [ %7, %3 ], [ %17, %16 ]
%14 = load i8, i8* %13
switch i8 %14, label %16 [
i8 0, label %18
i8 46, label %15
]
15: ; preds = %12
store i8 0, i8* %13
br label %18
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %13, i64 1
br label %12
18: ; preds = %12, %15
%19 = icmp eq i32 %2, 0
%20 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1900
%23 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 1
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1
%26 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 2
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 3
%29 = load i32, i32* %28
%30 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 4
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %10, i64 0, i32 5
%33 = load i32, i32* %32
br i1 %19, label %39, label %34
34: ; preds = %18
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%36 = load i32, i32* %35
%37 = sdiv i32 %36, 1000
%38 = call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, i32, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %25, i32 %27, i32 %29, i32 %31, i32 %33, i32 %37, i8* %7)
br label %41
39: ; preds = %18
%40 = call i32 (i8*, i32, i8*, i32, i32, i32, i32, i32, i32, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %25, i32 %27, i32 %29, i32 %31, i32 %33, i8* %7)
br label %41
41: ; preds = %39, %34
ret void
}