#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*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void format_time() {
  printf("Formatting Time with strftime\n");
  time_t raw_time;
  struct tm *timeinfo;
  char buffer[200];
  time(&raw_time);
  timeinfo = localtime(&raw_time);
  strftime(buffer, 200, "Now it's %I:%M%p.", timeinfo);
  puts(buffer);
  strftime(
      buffer, 200,
      "Today it is %A, %d of %B, %Y. Day of number %j. Offset from UTC %z.",
      timeinfo);
  puts(buffer);
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
lea    0xe9e(%rip),%rdi
call   1050 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1060 <time@plt>
lea    -0x4(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x10(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xc8,%esi
lea    0xe8b(%rip),%rdx
call   1070 <strftime@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <puts@plt>
lea    -0xe0(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xc8,%esi
lea    0xe75(%rip),%rdx
call   1070 <strftime@plt>
lea    -0xe0(%rbp),%rdi
call   1040 <puts@plt>
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
push   %r14
push   %rbx
sub    $0xd8,%rsp
lea    0xf05(%rip),%rdi
call   1040 <puts@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <time@plt>
mov    %rbx,%rdi
call   1030 <localtime@plt>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rax,%rcx
call   1060 <strftime@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
lea    0xe79(%rip),%rdx
mov    %r14,%rdi
mov    $0xc8,%esi
mov    %rbx,%rcx
call   1060 <strftime@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [31 x i8] c"Formatting Time with strftime\0A\00"
@.str.1 = [18 x i8] c"Now it's %I:%M%p.\00"
@.str.2 = [68 x i8] c"Today it is %A, %d of %B, %Y. Day of number %j. Offset from UTC %z.\00"
define void @format_time() {
%1 = alloca i32
%2 = alloca %struct.tm*
%3 = alloca [200 x i8]
%4 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @time(i32* %1)
%6 = call %struct.tm* @localtime(i32* %1)
store %struct.tm* %6, %struct.tm** %2
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%8 = load %struct.tm*, %struct.tm** %2
%9 = call i32 @strftime(i8* %7, i32 200, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %8)
%10 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%11 = call i32 @puts(i8* %10)
%12 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%13 = load %struct.tm*, %struct.tm** %2
%14 = call i32 @strftime(i8* %12, i32 200, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %13)
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%16 = call i32 @puts(i8* %15)
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str.1 = [18 x i8] c"Now it's %I:%M%p.\00"
@.str.2 = [68 x i8] c"Today it is %A, %d of %B, %Y. Day of number %j. Offset from UTC %z.\00"
@str = [30 x i8] c"Formatting Time with strftime\00"
define void @format_time() {
%1 = alloca i32
%2 = alloca [200 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%6 = call i32 @time(i32* %1)
%7 = call %struct.tm* @localtime(i32* %1)
%8 = call i32 @strftime(i8* %5, i32 200, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %7)
%9 = call i32 @puts(i8* %5)
%10 = call i32 @strftime(i8* %5, i32 200, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %7)
%11 = call i32 @puts(i8* %5)
ret void
}