#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 tm_year;
  int tm_mon;
  int tm_mday;
  int tm_sec;
  int tm_isdst;
  scalar_t__ tm_min;
  scalar_t__ tm_hour;
};
typedef int /*<<< orphan*/ datebuff;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int mktime(struct tm *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
char *date(int d, int m, int y) {
  struct tm date;
  static char datebuff[10];
  date.tm_year = y - 1900;
  date.tm_mon = m - 1;
  date.tm_mday = d;
  date.tm_hour = 0;
  date.tm_min = 0;
  date.tm_sec = 1;
  date.tm_isdst = -1;
  if (mktime(&date) == -1) {
    printf("Making time using mktime() failed.\nExiting program ..\n");
    exit(1);
  } else {
    strftime(datebuff, sizeof(datebuff), "%A", &date);
    return datebuff;
  }
}


x86 assembly (clang, -O0):
<date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0xffffffff,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
call   1040 <mktime@plt>
cmp    $0xffffffff,%eax
jne    11b1 <date+0x71>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0x2e89(%rip),%rdi
mov    $0xa,%esi
lea    0xe73(%rip),%rdx
lea    -0x38(%rbp),%rcx
call   1050 <strftime@plt>
lea    0x2e6d(%rip),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<date>:
push   %rbx
sub    $0x30,%rsp
add    $0xfffff894,%edx
mov    %edx,0x8(%rsp)
add    $0xffffffff,%esi
mov    %esi,0xc(%rsp)
mov    %edi,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x20(%rsp)
movabs $0xffffffff00000001,%rax
ff ff ff
mov    %rax,0x14(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <mktime@plt>
cmp    $0xffffffff,%eax
je     11a9 <date+0x69>
lea    0x2eba(%rip),%rbx
lea    0xe72(%rip),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strftime@plt>
mov    %rbx,%rax
add    $0x30,%rsp
pop    %rbx
ret
lea    0xe53(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i64, i64 }
@date.datebuff = internal global [10 x i8] zeroinitializer
@.str = [55 x i8] c"Making time using mktime() failed.\0AExiting program ..\0A\00"
@.str.1 = [3 x i8] c"%A\00"
define i8* @date(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = sub nsw i32 %8, 1900
%10 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %5
%12 = sub nsw i32 %11, 1
%13 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* %4
%15 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 6
store i64 0, i64* %16
%17 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 5
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
store i32 1, i32* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 4
store i32 -1, i32* %19
%20 = call i32 @mktime(%struct.tm* %7)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %3
%26 = call i32 @strftime(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @date.datebuff, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %7)
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @date.datebuff, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i64, i64 }
@date.datebuff = internal global [10 x i8] zeroinitializer
@.str.1 = [3 x i8] c"%A\00"
@str = [54 x i8] c"Making time using mktime() failed.\0AExiting program ..\00"
define i8* @date(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.tm
%5 = bitcast %struct.tm* %4 to i8*
%6 = add nsw i32 %2, -1900
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
store i32 %6, i32* %7
%8 = add nsw i32 %1, -1
%9 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
store i32 %0, i32* %10
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%12 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%13 = bitcast i64* %11 to i8*
store i32 1, i32* %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
store i32 -1, i32* %14
%15 = call i32 @mktime(%struct.tm* %4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @str, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %3
%21 = call i32 @strftime(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @date.datebuff, i64 0, i64 0), i32 10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %4)
ret i8* getelementptr inbounds ([10 x i8], [10 x i8]* @date.datebuff, i64 0, i64 0)
}