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

/* Variables and functions */
int /*<<< orphan*/ abort();
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, long);
size_t strftime(char *, int, char *, struct tm *);
void printTimeString() {
  size_t charsWritten;
  char buffer[80];
  struct timeval tv;
  struct tm tm;
  if (gettimeofday(&tv, NULL) < 0) {
    printf("gettimeofday error\n");
    abort();
  }
  if (!localtime_r(&tv.tv_sec, &tm)) {
    printf("localtime_r error\n");
    abort();
  }
  charsWritten = strftime(buffer, 80, "%Y-%b-%d %H:%M:%S", &tm);
  if (charsWritten == 0) {
    printf("strftime error\n");
    abort();
  } else if (charsWritten > (80 - 7 - 1)) {
    printf("strftime overflow\n");
    abort();
  }
  snprintf(&buffer[charsWritten], 8, ".%06ld", (long)tv.tv_usec);
  printf("%s", buffer);
}


x86 assembly (clang, -O0):
<printTimeString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
cmp    $0x0,%rax
jge    1197 <printTimeString+0x37>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x70(%rbp),%rdi
add    $0x8,%rdi
lea    -0x78(%rbp),%rsi
call   1040 <localtime_r@plt>
cmp    $0x0,%eax
jne    11c6 <printTimeString+0x66>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
lea    0xe51(%rip),%rdx
lea    -0x78(%rbp),%rcx
call   1080 <strftime@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1203 <printTimeString+0xa3>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x48,-0x8(%rbp)
jbe    1223 <printTimeString+0xc3>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1228 <printTimeString+0xc8>
lea    -0x60(%rbp),%rdi
add    -0x8(%rbp),%rdi
mov    -0x70(%rbp),%rcx
mov    $0x8,%esi
lea    0xe1c(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printTimeString>:
sub    $0x78,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
test   %rax,%rax
js     11f4 <printTimeString+0x84>
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1040 <localtime_r@plt>
test   %eax,%eax
je     11fd <printTimeString+0x8d>
lea    0xe61(%rip),%rdx
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x50,%esi
call   1090 <strftime@plt>
test   %rax,%rax
je     1206 <printTimeString+0x96>
cmp    $0x49,%rax
jae    120f <printTimeString+0x9f>
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
mov    0x10(%rsp),%rcx
lea    0xe40(%rip),%rdx
mov    $0x8,%esi
call   1070 <snprintf@plt>
lea    0xe36(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x78,%rsp
ret
lea    0xe54(%rip),%rdi
jmp    1216 <printTimeString+0xa6>
lea    0xe18(%rip),%rdi
jmp    1216 <printTimeString+0xa6>
lea    0xe33(%rip),%rdi
jmp    1216 <printTimeString+0xa6>
lea    0xe18(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str = [20 x i8] c"gettimeofday error\0A\00"
@.str.1 = [19 x i8] c"localtime_r error\0A\00"
@.str.2 = [18 x i8] c"%Y-%b-%d %H:%M:%S\00"
@.str.3 = [16 x i8] c"strftime error\0A\00"
@.str.4 = [19 x i8] c"strftime overflow\0A\00"
@.str.5 = [7 x i8] c".%06ld\00"
@.str.6 = [3 x i8] c"%s\00"
define void @printTimeString() {
%1 = alloca i64
%2 = alloca [80 x i8]
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = call i64 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = call i32 (...) @abort()
unreachable
10: ; preds = %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%12 = call i32 @localtime_r(i32* %11, %struct.tm* %4)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 (...) @abort()
unreachable
17: ; preds = %10
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%19 = call i64 @strftime(i8* %18, i32 80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %4)
store i64 %19, i64* %1
%20 = load i64, i64* %1
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %17
%26 = load i64, i64* %1
%27 = icmp ugt i64 %26, 72
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i64, i64* %1
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%36 = load i64, i64* %35
%37 = call i32 @snprintf(i8* %34, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %36)
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %38)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32 }
@.str.2 = [18 x i8] c"%Y-%b-%d %H:%M:%S\00"
@.str.5 = [7 x i8] c".%06ld\00"
@.str.6 = [3 x i8] c"%s\00"
@str = [18 x i8] c"localtime_r error\00"
@str.7 = [18 x i8] c"strftime overflow\00"
@str.8 = [15 x i8] c"strftime error\00"
@str.9 = [19 x i8] c"gettimeofday error\00"
define void @printTimeString() {
%1 = alloca [80 x i8]
%2 = alloca %struct.timeval
%3 = alloca %struct.tm
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.tm* %3 to i8*
%7 = call i64 @gettimeofday(%struct.timeval* %2, i32* null)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %0
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%14 = call i32 @localtime_r(i32* %13, %struct.tm* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %12
%20 = call i64 @strftime(i8* %4, i32 80, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.8, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %19
%26 = icmp ugt i64 %20, 72
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %25
%31 = getelementptr inbounds [80 x i8], [80 x i8]* %1, i64 0, i64 %20
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%33 = load i64, i64* %32
%34 = call i32 @snprintf(i8* %31, i32 8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
ret void
}