#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;
};

/* Variables and functions */
int tm_diffdays(struct tm, struct tm, int *);
int tm_diffweeks(struct tm debut, struct tm fin, int *days, int *seconds) {
  int d = tm_diffdays(debut, fin, seconds);
  int s = seconds ? *seconds : 0;
  if (days)
    *days = d >= 0 ? d % 7 : -((-d) % 7);
  else if (seconds)
    *seconds = s;
  return d / 7;
}


x86 assembly (clang, -O0):
<tm_diffweeks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <tm_diffdays@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1151 <tm_diffweeks+0x41>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    115b <tm_diffweeks+0x4b>
xor    %eax,%eax
mov    %eax,-0x2c(%rbp)
jmp    115b <tm_diffweeks+0x4b>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ab <tm_diffweeks+0x9b>
cmpl   $0x0,-0x24(%rbp)
jl     1189 <tm_diffweeks+0x79>
mov    -0x24(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,-0x30(%rbp)
jmp    119d <tm_diffweeks+0x8d>
xor    %eax,%eax
sub    -0x24(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
sub    %edx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
jmp    11c4 <tm_diffweeks+0xb4>
cmpq   $0x0,-0x20(%rbp)
je     11bf <tm_diffweeks+0xaf>
mov    -0x28(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    11c4 <tm_diffweeks+0xb4>
mov    -0x24(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tm_diffweeks>:
push   %rbx
mov    %rdx,%rbx
mov    %rcx,%rdx
call   1030 <tm_diffdays@plt>
mov    %eax,%ecx
cltq
imul   $0xffffffff92492493,%rax,%rdx
shr    $0x20,%rdx
add    %edx,%eax
mov    %eax,%edx
shr    $0x1f,%edx
sar    $0x2,%eax
add    %edx,%eax
test   %rbx,%rbx
je     114b <tm_diffweeks+0x3b>
lea    0x0(,%rax,8),%edx
mov    %eax,%esi
sub    %edx,%esi
add    %esi,%ecx
mov    %ecx,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
define i32 @tm_diffweeks(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca %struct.tm
%6 = alloca %struct.tm
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i32 %0, i32* %11
%12 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i32 %1, i32* %12
store i32* %2, i32** %7
store i32* %3, i32** %8
%13 = load i32*, i32** %8
%14 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @tm_diffdays(i32 %15, i32 %17, i32* %13)
store i32 %18, i32* %9
%19 = load i32*, i32** %8
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %4
%22 = load i32*, i32** %8
%23 = load i32, i32* %22
br label %25
24: ; preds = %4
br label %25
25: ; preds = %24, %21
%26 = phi i32 [ %23, %21 ], [ 0, %24 ]
store i32 %26, i32* %10
%27 = load i32*, i32** %7
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load i32, i32* %9
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %9
%34 = srem i32 %33, 7
br label %40
35: ; preds = %29
%36 = load i32, i32* %9
%37 = sub nsw i32 0, %36
%38 = srem i32 %37, 7
%39 = sub nsw i32 0, %38
br label %40
40: ; preds = %35, %32
%41 = phi i32 [ %34, %32 ], [ %39, %35 ]
%42 = load i32*, i32** %7
store i32 %41, i32* %42
br label %50
43: ; preds = %25
%44 = load i32*, i32** %8
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i32, i32* %10
%48 = load i32*, i32** %8
store i32 %47, i32* %48
br label %49
49: ; preds = %46, %43
br label %50
50: ; preds = %49, %40
%51 = load i32, i32* %9
%52 = sdiv i32 %51, 7
ret i32 %52
}

LLVM IR (-O2):
define i32 @tm_diffweeks(i32 %0, i32 %1, i32* writeonly %2, i32* %3) {
%5 = tail call i32 @tm_diffdays(i32 %0, i32 %1, i32* %3)
%6 = icmp eq i32* %2, null
%7 = sdiv i32 %5, 7
%8 = srem i32 %5, 7
br i1 %6, label %10, label %9
9: ; preds = %4
store i32 %8, i32* %2
br label %10
10: ; preds = %4, %9
ret i32 %7
}