#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_mday;
  int tm_mon;
  int tm_year;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktime(struct tm *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int dayintheweek(int ditw) {
  int ys, ms, ds;
  struct tm ts;
  time_t tts;
  char wday[4];
  ys = ditw / 10000;
  ms = ditw - (ditw / 100);
  ds = ditw - ((ys * 10000) + (ms * 100));
  ts.tm_mday = ds;
  ts.tm_mon = ms - 1;
  ts.tm_year = ys - 1900;
  ts.tm_hour = ts.tm_min = ts.tm_sec = 1;
  tts = mktime(&ts);
  strncpy(wday, ctime(&tts), 3);
  if (strcmp(wday, "Sat") == 0 || strcmp(wday, "Sun") == 0)
    return 0;
  else
    return 1;
}


x86 assembly (clang, -O0):
<dayintheweek>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
imul   $0x2710,-0xc(%rbp),%ecx
imul   $0x64,-0x10(%rbp),%edx
add    %edx,%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x28(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x34(%rbp)
lea    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x34(%rbp),%rdi
call   1040 <ctime@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x38(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1219 <dayintheweek+0xd9>
lea    -0x38(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1225 <dayintheweek+0xe5>
movl   $0x0,-0x4(%rbp)
jmp    122c <dayintheweek+0xec>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayintheweek>:
push   %rbx
sub    $0x20,%rsp
movslq %edi,%rdx
imul   $0x68db8bad,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
lea    (%rax,%rcx,1),%esi
imul   $0xffffffffae147ae1,%rdx,%rdi
mov    %rdi,%rbx
shr    $0x3f,%rbx
sar    $0x25,%rdi
add    %ebx,%edi
lea    (%rdi,%rdx,1),%ebx
imul   $0xffffd8f0,%esi,%esi
imul   $0xffffff9c,%ebx,%ebx
add    %edx,%esi
add    %ebx,%esi
mov    %esi,0x8(%rsp)
add    %edi,%edx
add    $0xffffffff,%edx
mov    %edx,0xc(%rsp)
lea    -0x76c(%rax,%rcx,1),%eax
mov    %eax,0x10(%rsp)
movl   $0x1,0x1c(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x14(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <mktime@plt>
mov    %eax,(%rsp)
mov    %rsp,%rdi
call   1040 <ctime@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120b <dayintheweek+0xcb>
lea    0xe10(%rip),%rsi
lea    0x4(%rsp),%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    120d <dayintheweek+0xcd>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [4 x i8] c"Sat\00"
@.str.1 = [4 x i8] c"Sun\00"
define i32 @dayintheweek(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.tm
%8 = alloca i32
%9 = alloca [4 x i8]
store i32 %0, i32* %3
%10 = load i32, i32* %3
%11 = sdiv i32 %10, 10000
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = load i32, i32* %3
%14 = sdiv i32 %13, 100
%15 = sub nsw i32 %12, %14
store i32 %15, i32* %5
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = mul nsw i32 %17, 10000
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 100
%21 = add nsw i32 %18, %20
%22 = sub nsw i32 %16, %21
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1
%27 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1900
%30 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 5
store i32 1, i32* %31
%32 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 4
store i32 1, i32* %32
%33 = getelementptr inbounds %struct.tm, %struct.tm* %7, i32 0, i32 3
store i32 1, i32* %33
%34 = call i32 @mktime(%struct.tm* %7)
store i32 %34, i32* %8
%35 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%36 = call i32 @ctime(i32* %8)
%37 = call i32 @strncpy(i8* %35, i32 %36, i32 3)
%38 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%39 = call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %1
%42 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41, %1
store i32 0, i32* %2
br label %47
46: ; preds = %41
store i32 1, i32* %2
br label %47
47: ; preds = %46, %45
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [4 x i8] c"Sat\00"
@.str.1 = [4 x i8] c"Sun\00"
define i32 @dayintheweek(i32 %0) {
%2 = alloca %struct.tm
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = bitcast %struct.tm* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%8 = sdiv i32 %0, 10000
%9 = sdiv i32 %0, -100
%10 = add i32 %9, %0
%11 = mul nsw i32 %8, -10000
%12 = mul i32 %10, -100
%13 = add i32 %11, %0
%14 = add i32 %13, %12
%15 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i32 %14, i32* %15
%16 = add nsw i32 %10, -1
%17 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i32 %16, i32* %17
%18 = add nsw i32 %8, -1900
%19 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i32 1, i32* %20
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i32 1, i32* %21
%22 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i32 1, i32* %22
%23 = call i32 @mktime(%struct.tm* %2)
store i32 %23, i32* %3
%24 = call i32 @ctime(i32* %3)
%25 = call i32 @strncpy(i8* %7, i32 %24, i32 3)
%26 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %1
%29 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %28, %1
%33 = phi i32 [ 0, %1 ], [ %31, %28 ]
ret i32 %33
}