#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 = 0, ms = 0, ds = 0;
  struct tm ts;
  time_t tts;
  char wday[4] = {'0', '0', '0', '0'};
  ys = ditw / 10000;
  ms = (ditw - (ys * 10000)) / 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    $0x40,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0xe9a(%rip),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
imul   $0x2710,-0xc(%rbp),%ecx
sub    %ecx,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
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    0xdfa(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     1233 <dayintheweek+0xf3>
lea    -0x38(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123f <dayintheweek+0xff>
movl   $0x0,-0x4(%rbp)
jmp    1246 <dayintheweek+0x106>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dayintheweek>:
push   %rbx
sub    $0x20,%rsp
movl   $0x30303030,(%rsp)
movslq %edi,%rdx
imul   $0x68db8bad,%rdx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x2c,%rax
lea    (%rax,%rcx,1),%esi
imul   $0xffffd8f0,%esi,%esi
add    %esi,%edx
movslq %edx,%rdx
imul   $0x51eb851f,%rdx,%rsi
mov    %rsi,%rdi
shr    $0x3f,%rdi
sar    $0x25,%rsi
lea    (%rsi,%rdi,1),%ebx
imul   $0xffffff9c,%ebx,%ebx
add    %ebx,%edx
mov    %edx,0x8(%rsp)
lea    (%rsi,%rdi,1),%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,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <ctime@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1213 <dayintheweek+0xd3>
lea    0xe06(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    1215 <dayintheweek+0xd5>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

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

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 i32
%5 = bitcast %struct.tm* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 808464432, i32* %4
%8 = sdiv i32 %0, 10000
%9 = mul nsw i32 %8, -10000
%10 = add i32 %9, %0
%11 = sdiv i32 %10, 100
%12 = mul nsw i32 %11, -100
%13 = add i32 %10, %12
%14 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
store i32 %13, i32* %14
%15 = add nsw i32 %11, -1
%16 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 1
store i32 %15, i32* %16
%17 = add nsw i32 %8, -1900
%18 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 2
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 5
store i32 1, i32* %19
%20 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 4
store i32 1, i32* %20
%21 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 3
store i32 1, i32* %21
%22 = call i32 @mktime(%struct.tm* %2)
store i32 %22, i32* %3
%23 = call i32 @ctime(i32* %3)
%24 = call i32 @strncpy(i8* %7, i32 %23, i32 3)
%25 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %1
%28 = call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
%30 = zext i1 %29 to i32
br label %31
31: ; preds = %27, %1
%32 = phi i32 [ 0, %1 ], [ %30, %27 ]
ret i32 %32
}