#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 dummy;
};

/* Variables and functions */
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
char *getdatetime(char *now, int datetime) {
  time_t rawtime;
  struct tm *timeinfo;
  time(&rawtime);
  timeinfo = localtime(&rawtime);
  switch (datetime) {
  case 0:
    strftime(now, 10, "%Y%m%d", timeinfo);
    break;
  case 1:
    strftime(now, 10, "%R", timeinfo);
    break;
  case 2:
    strftime(now, 10, "%Y", timeinfo);
    break;
  default:
    strcpy(now, "no data");
    break;
  }
  return (now);
}


x86 assembly (clang, -O0):
<getdatetime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    %rdi,-0x28(%rbp)
call   1050 <time@plt>
mov    -0x28(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
test   %eax,%eax
je     119e <getdatetime+0x5e>
jmp    117c <getdatetime+0x3c>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
je     11bc <getdatetime+0x7c>
jmp    118d <getdatetime+0x4d>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     11da <getdatetime+0x9a>
jmp    11f8 <getdatetime+0xb8>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xa,%esi
lea    0xe4e(%rip),%rdx
call   1060 <strftime@plt>
jmp    1208 <getdatetime+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xa,%esi
lea    0xe37(%rip),%rdx
call   1060 <strftime@plt>
jmp    1208 <getdatetime+0xc8>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0xa,%esi
lea    0xe1c(%rip),%rdx
call   1060 <strftime@plt>
jmp    1208 <getdatetime+0xc8>
mov    -0x8(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdatetime>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
cmp    $0x2,%ebp
je     1179 <getdatetime+0x39>
cmp    $0x1,%ebp
je     1182 <getdatetime+0x42>
test   %ebp,%ebp
jne    119b <getdatetime+0x5b>
lea    0xe89(%rip),%rdx
jmp    1189 <getdatetime+0x49>
lea    0xe8a(%rip),%rdx
jmp    1189 <getdatetime+0x49>
lea    0xe7e(%rip),%rdx
mov    %r14,%rdi
mov    $0xa,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
jmp    11aa <getdatetime+0x6a>
lea    0xe6b(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%Y%m%d\00"
@.str.1 = [3 x i8] c"%R\00"
@.str.2 = [3 x i8] c"%Y\00"
@.str.3 = [8 x i8] c"no data\00"
define i8* @getdatetime(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 @time(i32* %5)
%8 = call %struct.tm* @localtime(i32* %5)
store %struct.tm* %8, %struct.tm** %6
%9 = load i32, i32* %4
switch i32 %9, label %22 [
i32 0, label %10
i32 1, label %14
i32 2, label %18
]
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = load %struct.tm*, %struct.tm** %6
%13 = call i32 @strftime(i8* %11, i32 10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %12)
br label %25
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = load %struct.tm*, %struct.tm** %6
%17 = call i32 @strftime(i8* %15, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %16)
br label %25
18: ; preds = %2
%19 = load i8*, i8** %3
%20 = load %struct.tm*, %struct.tm** %6
%21 = call i32 @strftime(i8* %19, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %20)
br label %25
22: ; preds = %2
%23 = load i8*, i8** %3
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %25
25: ; preds = %22, %18, %14, %10
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%Y%m%d\00"
@.str.1 = [3 x i8] c"%R\00"
@.str.2 = [3 x i8] c"%Y\00"
@.str.3 = [8 x i8] c"no data\00"
define i8* @getdatetime(i8* returned %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @time(i32* %3)
%6 = call %struct.tm* @localtime(i32* %3)
switch i32 %1, label %13 [
i32 0, label %7
i32 1, label %9
i32 2, label %11
]
7: ; preds = %2
%8 = call i32 @strftime(i8* %0, i32 10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %6)
br label %15
9: ; preds = %2
%10 = call i32 @strftime(i8* %0, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %6)
br label %15
11: ; preds = %2
%12 = call i32 @strftime(i8* %0, i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %6)
br label %15
13: ; preds = %2
%14 = call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %11, %9, %7
ret i8* %0
}