#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_string;
struct tm {
  int dummy;
};
struct timeval {
  int tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
void get_time(char *btime, int mode) {
  struct timeval tv;
  struct tm *ptm;
  char time_string[40];
  long milliseconds;
  gettimeofday(&tv, NULL);
  ptm = gmtime(&tv.tv_sec);
  strftime(time_string, sizeof(time_string), "%Y%m%d%H%M%S", ptm);
  milliseconds = tv.tv_usec / 1000;
  switch (mode) {
  case 1:
    sprintf(btime, "%s", time_string);
    break;
  case 2:
    sprintf(btime, "%s.%03ld", time_string, milliseconds);
    break;
  case 3:
    sprintf(btime, "%s.%u", time_string, (unsigned int)tv.tv_usec);
    break;
  case 4:
    memset(time_string, '\0', sizeof(time_string));
    strftime(time_string, sizeof(time_string), "%H:%M:%S", ptm);
    sprintf(btime, "%s", time_string);
    break;
  }
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdi
call   1030 <gettimeofday@plt>
lea    -0x14(%rbp),%rdi
call   1060 <gmtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
lea    0xe8c(%rip),%rdx
lea    -0x50(%rbp),%rdi
mov    $0x28,%esi
call   1050 <strftime@plt>
movslq -0x18(%rbp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x3,%eax
ja     1270 <get_time+0x120>
mov    -0x60(%rbp),%rax
lea    0xe30(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1270 <get_time+0x120>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    -0x58(%rbp),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1270 <get_time+0x120>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
mov    -0x18(%rbp),%ecx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1270 <get_time+0x120>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x28,%esi
lea    0xdda(%rip),%rdx
call   1050 <strftime@plt>
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
lea    0xc(%rsp),%rdi
call   1070 <gmtime@plt>
mov    %rax,%r15
lea    0xe82(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x28,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
add    $0xffffffff,%ebx
cmp    $0x3,%ebx
ja     124a <get_time+0xea>
mov    0x8(%rsp),%ecx
lea    0xe49(%rip),%rax
movslq (%rax,%rbx,4),%rdx
add    %rax,%rdx
jmp    *%rdx
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
jmp    1245 <get_time+0xe5>
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rcx
lea    0xe32(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    124a <get_time+0xea>
lea    0xe23(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    124a <get_time+0xea>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
lea    0xdfd(%rip),%rdx
mov    %rbx,%rdi
mov    $0x28,%esi
mov    %r15,%rcx
call   1060 <strftime@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [13 x i8] c"%Y%m%d%H%M%S\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"%s.%03ld\00"
@.str.3 = [6 x i8] c"%s.%u\00"
@.str.4 = [9 x i8] c"%H:%M:%S\00"
define void @get_time(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca %struct.tm*
%7 = alloca [40 x i8]
%8 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%11 = call %struct.tm* @gmtime(i32* %10)
store %struct.tm* %11, %struct.tm** %6
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%13 = load %struct.tm*, %struct.tm** %6
%14 = call i32 @strftime(i8* %12, i32 40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.tm* %13)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%16 = load i32, i32* %15
%17 = sdiv i32 %16, 1000
%18 = sext i32 %17 to i64
store i64 %18, i64* %8
%19 = load i32, i32* %4
switch i32 %19, label %44 [
i32 1, label %20
i32 2, label %24
i32 3, label %29
i32 4, label %35
]
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%23 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %44
24: ; preds = %2
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%27 = load i64, i64* %8
%28 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %26, i64 %27)
br label %44
29: ; preds = %2
%30 = load i8*, i8** %3
%31 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 %33)
br label %44
35: ; preds = %2
%36 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%37 = call i32 @memset(i8* %36, i8 signext 0, i32 40)
%38 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%39 = load %struct.tm*, %struct.tm** %6
%40 = call i32 @strftime(i8* %38, i32 40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %39)
%41 = load i8*, i8** %3
%42 = getelementptr inbounds [40 x i8], [40 x i8]* %7, i64 0, i64 0
%43 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %2, %35, %29, %24, %20
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.tm = type { i32 }
@.str = [13 x i8] c"%Y%m%d%H%M%S\00"
@.str.2 = [9 x i8] c"%s.%03ld\00"
@.str.3 = [6 x i8] c"%s.%u\00"
@.str.4 = [9 x i8] c"%H:%M:%S\00"
define void @get_time(i8* %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca [40 x i8]
%5 = bitcast %struct.timeval* %3 to i8*
%6 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = call %struct.tm* @gmtime(i32* %8)
%10 = call i32 @strftime(i8* %6, i32 40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %struct.tm* %9)
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%12 = load i32, i32* %11
switch i32 %1, label %25 [
i32 1, label %13
i32 2, label %15
i32 3, label %19
i32 4, label %21
]
13: ; preds = %2
%14 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* %6)
br label %25
15: ; preds = %2
%16 = sdiv i32 %12, 1000
%17 = sext i32 %16 to i64
%18 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %6, i64 %17)
br label %25
19: ; preds = %2
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %6, i32 %12)
br label %25
21: ; preds = %2
%22 = call i32 @memset(i8* %6, i8 signext 0, i32 40)
%23 = call i32 @strftime(i8* %6, i32 40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %struct.tm* %9)
%24 = call i8* @strcpy(i8* dereferenceable(1) %0, i8* %6)
br label %25
25: ; preds = %2, %21, %19, %15, %13
ret void
}