#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;
};
typedef int /*<<< orphan*/ str;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
struct tm *gmtime(int /*<<< orphan*/ *);
struct tm *localtime(int /*<<< orphan*/ *);
scalar_t__ optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char str[256], *fmt;
  struct tm *tm;
  time_t t;
  int opt, utc;
  utc = 0;
  while ((opt = getopt(argc, argv, "u")) != -1) {
    switch (opt) {
    case 'u':
      utc = 1;
      break;
    }
  }
  argc -= optind;
  argv += optind;
  fmt = "%Y-%m-%d_%02k-%02M";
  if (argc >= 2)
    fmt = argv[1];
  t = time(NULL);
  if (utc)
    tm = gmtime(&t);
  else
    tm = localtime(&t);
  if (!tm) {
    perror(utc ? "gmtime" : "localtime");
    return 1;
  }
  if (strftime(str, sizeof(str), fmt, tm) == 0) {
    fprintf(stderr, "invalid strftime format\n");
    return 1;
  }
  printf("%s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x128(%rbp)
cmp    $0xffffffff,%eax
je     11e8 <main+0x68>
mov    -0x128(%rbp),%eax
sub    $0x75,%eax
jne    11e3 <main+0x63>
jmp    11d9 <main+0x59>
movl   $0x1,-0x12c(%rbp)
jmp    11a3 <main+0x23>
mov    0x2df9(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0xde9(%rip),%rax
mov    %rax,-0x118(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1239 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x118(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x12c(%rbp)
je     126d <main+0xed>
lea    -0x124(%rbp),%rdi
call   1090 <gmtime@plt>
mov    %rax,-0x120(%rbp)
jmp    1280 <main+0x100>
lea    -0x124(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x120(%rbp)
cmpq   $0x0,-0x120(%rbp)
jne    12ba <main+0x13a>
mov    -0x12c(%rbp),%ecx
lea    0xd81(%rip),%rdi
lea    0xd73(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    131e <main+0x19e>
lea    -0x110(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    -0x120(%rbp),%rcx
mov    $0x100,%esi
call   1070 <strftime@plt>
cmp    $0x0,%rax
jne    1304 <main+0x184>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd33(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    131e <main+0x19e>
lea    -0x110(%rbp),%rsi
lea    0xd2d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r15b
lea    0xe64(%rip),%r14
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10a0 <getopt@plt>
cmp    $0x75,%eax
je     11b9 <main+0x39>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x20>
jmp    11be <main+0x3e>
xor    %r15d,%r15d
jmp    11a0 <main+0x20>
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
sub    %eax,%ebp
cmp    $0x2,%ebp
jl     11d6 <main+0x56>
mov    0x8(%rbx,%rax,8),%rbx
jmp    11dd <main+0x5d>
lea    0xe25(%rip),%rbx
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rdi
test   $0x1,%r15b
je     122c <main+0xac>
call   1030 <localtime@plt>
test   %rax,%rax
je     1236 <main+0xb6>
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
je     1253 <main+0xd3>
lea    0xe21(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    126d <main+0xed>
call   1090 <gmtime@plt>
test   %rax,%rax
jne    11fd <main+0x7d>
lea    0xddf(%rip),%rax
lea    0xdd1(%rip),%rdi
test   $0x1,%r15b
cmovne %rax,%rdi
call   1080 <perror@plt>
jmp    1268 <main+0xe8>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [2 x i8] c"u\00"
@optind = global i64 0
@.str.1 = [19 x i8] c"%Y-%m-%d_%02k-%02M\00"
@.str.2 = [7 x i8] c"gmtime\00"
@.str.3 = [10 x i8] c"localtime\00"
@stderr = global i32 0
@.str.4 = [25 x i8] c"invalid strftime format\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i8*
%8 = alloca %struct.tm*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %10
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* %10
switch i32 %18, label %20 [
i32 117, label %19
]
19: ; preds = %17
store i32 1, i32* %11
br label %20
20: ; preds = %17, %19
br label %12
21: ; preds = %12
%22 = load i64, i64* @optind
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = sub nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %4
%27 = load i64, i64* @optind
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 %27
store i8** %29, i8*** %5
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8** %7
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 2
br i1 %31, label %32, label %36
32: ; preds = %21
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
store i8* %35, i8** %7
br label %36
36: ; preds = %32, %21
%37 = call i32 @time(i32* null)
store i32 %37, i32* %9
%38 = load i32, i32* %11
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call %struct.tm* @gmtime(i32* %9)
store %struct.tm* %41, %struct.tm** %8
br label %44
42: ; preds = %36
%43 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %43, %struct.tm** %8
br label %44
44: ; preds = %42, %40
%45 = load %struct.tm*, %struct.tm** %8
%46 = icmp ne %struct.tm* %45, null
br i1 %46, label %53, label %47
47: ; preds = %44
%48 = load i32, i32* %11
%49 = icmp ne i32 %48, 0
%50 = zext i1 %49 to i64
%51 = select i1 %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0)
%52 = call i32 @perror(i8* %51)
store i32 1, i32* %3
br label %65
53: ; preds = %44
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%55 = load i8*, i8** %7
%56 = load %struct.tm*, %struct.tm** %8
%57 = call i64 @strftime(i8* %54, i32 256, i8* %55, %struct.tm* %56)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %65
62: ; preds = %53
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %63)
store i32 0, i32* %3
br label %65
65: ; preds = %62, %59, %47
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [2 x i8] c"u\00"
@optind = global i64 0
@.str.1 = [19 x i8] c"%Y-%m-%d_%02k-%02M\00"
@.str.2 = [7 x i8] c"gmtime\00"
@.str.3 = [10 x i8] c"localtime\00"
@stderr = global i32 0
@.str.4 = [25 x i8] c"invalid strftime format\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
br label %7
7: ; preds = %9, %2
%8 = phi i1 [ true, %2 ], [ false, %9 ]
br label %9
9: ; preds = %7, %9
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %9 [
i32 -1, label %11
i32 117, label %7
]
11: ; preds = %9
%12 = load i64, i64* @optind
%13 = trunc i64 %12 to i32
%14 = sub i32 %0, %13
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 %12
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
br label %20
20: ; preds = %16, %11
%21 = phi i8* [ %19, %16 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %11 ]
%22 = tail call i32 @time(i32* null)
store i32 %22, i32* %4
br i1 %8, label %25, label %23
23: ; preds = %20
%24 = call %struct.tm* @gmtime(i32* %4)
br label %27
25: ; preds = %20
%26 = call %struct.tm* @localtime(i32* %4)
br label %27
27: ; preds = %25, %23
%28 = phi %struct.tm* [ %24, %23 ], [ %26, %25 ]
%29 = icmp eq %struct.tm* %28, null
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = select i1 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%32 = call i32 @perror(i8* %31)
br label %41
33: ; preds = %27
%34 = call i64 @strftime(i8* %5, i32 256, i8* %21, %struct.tm* %28)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %41
39: ; preds = %33
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %5)
br label %41
41: ; preds = %39, %36, %30
%42 = phi i32 [ 1, %36 ], [ 0, %39 ], [ 1, %30 ]
ret i32 %42
}