#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 tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_wday;
};
typedef char chtype;
typedef int /*<<< orphan*/ buff;
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
char A_BOLD;
char const A_REVERSE;
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ waddch(int /*<<< orphan*/ *, char const);
int /*<<< orphan*/ wmove(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void curses_timestamp(void *ui) {
  WINDOW *win = ui;
  struct tm local_now;
  time_t time_now;
  char buff[256];
  int i;
  const chtype day_of_week[7] = {'S', 'M', 'T', 'W', 'T', 'F', 'S'};
  time(&time_now);
  localtime_r(&time_now, &local_now);
  snprintf(buff, sizeof(buff), "%2d-%2d %2d:%02d", local_now.tm_mon,
           local_now.tm_mday, local_now.tm_hour, local_now.tm_min);
  wmove(win, 0, 0);
  for (i = 0; buff[i] != 0; i++) {
    waddch(win, A_BOLD | buff[i]);
  }
  wmove(win, 1, 0);
  for (i = 0; i < 7; i++) {
    waddch(win, ((i == local_now.tm_wday) ? 0 : A_REVERSE) | day_of_week[i]);
  }
}


x86 assembly (clang, -O0):
<curses_timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x160,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0xe93(%rip),%eax
mov    %eax,-0x13b(%rbp)
mov    0xe8a(%rip),%ax
mov    %ax,-0x137(%rbp)
mov    0xe7f(%rip),%al
mov    %al,-0x135(%rbp)
lea    -0x2c(%rbp),%rdi
call   1060 <time@plt>
lea    -0x2c(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <localtime_r@plt>
lea    -0x130(%rbp),%rdi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9d
mov    -0x1c(%rbp),%eax
mov    $0x100,%esi
lea    0xe44(%rip),%rdx
mov    %eax,(%rsp)
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <wmove@plt>
movl   $0x0,-0x134(%rbp)
movslq -0x134(%rbp),%rax
movsbl -0x130(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1236 <curses_timestamp+0xe6>
mov    -0x10(%rbp),%rdi
mov    0x2dd2(%rip),%rax
movsbl (%rax),%eax
movslq -0x134(%rbp),%rcx
movsbl -0x130(%rbp,%rcx,1),%ecx
ff
or     %ecx,%eax
movsbl %al,%esi
call   1040 <waddch@plt>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    11e3 <curses_timestamp+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <wmove@plt>
movl   $0x0,-0x134(%rbp)
cmpl   $0x7,-0x134(%rbp)
jge    12ce <curses_timestamp+0x17e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1284 <curses_timestamp+0x134>
xor    %eax,%eax
mov    %eax,-0x14c(%rbp)
jmp    1294 <curses_timestamp+0x144>
mov    0x2d55(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    -0x148(%rbp),%rdi
mov    -0x14c(%rbp),%eax
movslq -0x134(%rbp),%rcx
movsbl -0x13b(%rbp,%rcx,1),%ecx
ff
or     %ecx,%eax
movsbl %al,%esi
call   1040 <waddch@plt>
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1250 <curses_timestamp+0x100>
add    $0x160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curses_timestamp>:
push   %r15
push   %r14
push   %rbx
sub    $0x120,%rsp
mov    %rdi,%r15
lea    0x1c(%rsp),%r14
mov    %r14,%rdi
call   1060 <time@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1030 <localtime_r@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
mov    0x10(%rsp),%r9d
mov    0x14(%rsp),%eax
mov    %eax,(%rsp)
lea    0xe6b(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <wmove@plt>
mov    0x20(%rsp),%al
test   %al,%al
je     11e9 <curses_timestamp+0x99>
lea    0x21(%rsp),%rbx
mov    0x2e1c(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
or     (%r14),%al
movsbl %al,%esi
mov    %r15,%rdi
call   1040 <waddch@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11d0 <curses_timestamp+0x80>
mov    %r15,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <wmove@plt>
mov    %r15,%rdi
mov    $0x53,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x4d,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x54,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x57,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x54,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x46,%esi
call   1040 <waddch@plt>
mov    %r15,%rdi
mov    $0x53,%esi
call   1040 <waddch@plt>
add    $0x120,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32 }
@__const.curses_timestamp.day_of_week = [7 x i8] c"SMTWTFS"
@.str = [17 x i8] c"%2d-%2d %2d:%02d\00"
@A_BOLD = global i8 0
@A_REVERSE = constant i8 0
define void @curses_timestamp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.tm
%5 = alloca i32
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca [7 x i8]
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %3
%11 = bitcast [7 x i8]* %8 to i8*
%12 = call i32 @time(i32* %5)
%13 = call i32 @localtime_r(i32* %5, %struct.tm* %4)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 2
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 3
%22 = load i32, i32* %21
%23 = call i32 @snprintf(i8* %14, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %20, i32 %22)
%24 = load i32*, i32** %3
%25 = call i32 @wmove(i32* %24, i32 0, i32 0)
store i32 0, i32* %7
br label %26
26: ; preds = %45, %1
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %48
33: ; preds = %26
%34 = load i32*, i32** %3
%35 = load i8, i8* @A_BOLD
%36 = sext i8 %35 to i32
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = or i32 %36, %41
%43 = trunc i32 %42 to i8
%44 = call i32 @waddch(i32* %34, i8 signext %43)
br label %45
45: ; preds = %33
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %26
48: ; preds = %26
%49 = load i32*, i32** %3
%50 = call i32 @wmove(i32* %49, i32 1, i32 0)
store i32 0, i32* %7
br label %51
51: ; preds = %74, %48
%52 = load i32, i32* %7
%53 = icmp slt i32 %52, 7
br i1 %53, label %54, label %77
54: ; preds = %51
%55 = load i32*, i32** %3
%56 = load i32, i32* %7
%57 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 4
%58 = load i32, i32* %57
%59 = icmp eq i32 %56, %58
br i1 %59, label %60, label %61
60: ; preds = %54
br label %64
61: ; preds = %54
%62 = load i8, i8* @A_REVERSE
%63 = sext i8 %62 to i32
br label %64
64: ; preds = %61, %60
%65 = phi i32 [ 0, %60 ], [ %63, %61 ]
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = or i32 %65, %70
%72 = trunc i32 %71 to i8
%73 = call i32 @waddch(i32* %55, i8 signext %72)
br label %74
74: ; preds = %64
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %51
77: ; preds = %51
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32 }
@.str = [17 x i8] c"%2d-%2d %2d:%02d\00"
@A_BOLD = global i8 0
@A_REVERSE = constant i8 0
define void @curses_timestamp(i8* %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = bitcast i8* %0 to i32*
%6 = bitcast %struct.tm* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%9 = call i32 @time(i32* %3)
%10 = call i32 @localtime_r(i32* %3, %struct.tm* %2)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
%14 = load i32, i32* %13
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
%18 = load i32, i32* %17
%19 = call i32 @snprintf(i8* %8, i32 256, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %14, i32 %16, i32 %18)
%20 = call i32 @wmove(i32* %5, i32 0, i32 0)
%21 = load i8, i8* %8
%22 = icmp eq i8 %21, 0
br i1 %22, label %33, label %23
23: ; preds = %1, %23
%24 = phi i64 [ %29, %23 ], [ 0, %1 ]
%25 = phi i8 [ %31, %23 ], [ %21, %1 ]
%26 = load i8, i8* @A_BOLD
%27 = or i8 %26, %25
%28 = call i32 @waddch(i32* %5, i8 signext %27)
%29 = add nuw i64 %24, 1
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %23
33: ; preds = %23, %1
%34 = call i32 @wmove(i32* %5, i32 1, i32 0)
%35 = call i32 @waddch(i32* %5, i8 signext 83)
%36 = call i32 @waddch(i32* %5, i8 signext 77)
%37 = call i32 @waddch(i32* %5, i8 signext 84)
%38 = call i32 @waddch(i32* %5, i8 signext 87)
%39 = call i32 @waddch(i32* %5, i8 signext 84)
%40 = call i32 @waddch(i32* %5, i8 signext 70)
%41 = call i32 @waddch(i32* %5, i8 signext 83)
ret void
}