#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*/ *);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ puts(char *);
size_t strftime(char *, size_t, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  size_t buffersz = 4096;
  char *buffer = malloc(buffersz);
  if (buffer == NULL) {
    perror("malloc hates me: ");
    return 1;
  }
  time_t now_seconds = time(NULL);
  struct tm *now = localtime(&now_seconds);
  int i;
  for (i = 1; i < argc; i++) {
    size_t outputsz;
    char *fmt = argv[i];
    outputsz = strftime(buffer, buffersz, fmt, now);
    if (outputsz != 0) {
      puts(buffer);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1000,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ae <main+0x4e>
lea    0xe63(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1231 <main+0xd1>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    122a <main+0xca>
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1070 <strftime@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1217 <main+0xb7>
mov    -0x20(%rbp),%rdi
call   1040 <puts@plt>
jmp    121c <main+0xbc>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11ce <main+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
mov    $0x1000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11dc <main+0x7c>
mov    %rax,%rbx
xor    %r14d,%r14d
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <localtime@plt>
cmp    $0x2,%ebp
jl     11ee <main+0x8e>
mov    %rax,%r12
mov    %ebp,%r13d
mov    $0x1,%ebp
jmp    11b9 <main+0x59>
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %rbp,%r13
je     11ee <main+0x8e>
mov    (%r15,%rbp,8),%rdx
mov    $0x1000,%esi
mov    %rbx,%rdi
mov    %r12,%rcx
call   1070 <strftime@plt>
test   %rax,%rax
je     11b0 <main+0x50>
mov    %rbx,%rdi
call   1040 <puts@plt>
jmp    11b0 <main+0x50>
lea    0xe1d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [18 x i8] c"malloc hates me: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.tm*
%10 = alloca i32
%11 = alloca i64
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 4096, i64* %6
%13 = load i64, i64* %6
%14 = call i8* @malloc(i64 %13)
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
19: ; preds = %2
%20 = call i32 @time(i32* null)
store i32 %20, i32* %8
%21 = call %struct.tm* @localtime(i32* %8)
store %struct.tm* %21, %struct.tm** %9
store i32 1, i32* %10
br label %22
22: ; preds = %43, %19
%23 = load i32, i32* %10
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = load i8**, i8*** %5
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %12
%32 = load i8*, i8** %7
%33 = load i64, i64* %6
%34 = load i8*, i8** %12
%35 = load %struct.tm*, %struct.tm** %9
%36 = call i64 @strftime(i8* %32, i64 %33, i8* %34, %struct.tm* %35)
store i64 %36, i64* %11
%37 = load i64, i64* %11
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %26
%40 = load i8*, i8** %7
%41 = call i32 @puts(i8* %40)
br label %42
42: ; preds = %39, %26
br label %43
43: ; preds = %42
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %22
46: ; preds = %22
store i32 0, i32* %3
br label %47
47: ; preds = %46, %17
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [18 x i8] c"malloc hates me: \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = tail call dereferenceable_or_null(4096) i8* @malloc(i64 4096)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
%10 = tail call i32 @time(i32* null)
store i32 %10, i32* %3
%11 = call %struct.tm* @localtime(i32* %3)
%12 = icmp sgt i32 %0, 1
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %23
%16 = phi i64 [ 1, %13 ], [ %24, %23 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @strftime(i8* %4, i64 4096, i8* %18, %struct.tm* %11)
%20 = icmp eq i64 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = call i32 @puts(i8* %4)
br label %23
23: ; preds = %21, %15
%24 = add nuw nsw i64 %16, 1
%25 = icmp eq i64 %24, %14
br i1 %25, label %26, label %15
26: ; preds = %23, %8
br label %27
27: ; preds = %26, %6
%28 = phi i32 [ 1, %6 ], [ 0, %26 ]
ret i32 %28
}