#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_wday;
  int tm_yday;
};

/* Variables and functions */
int week(struct tm *t) {
  int dow;
  int weeks;
  int yday;
  dow = (t->tm_wday == 0) ? 7 : t->tm_wday;
  yday = (t->tm_yday + 1);
  weeks = yday / 7;
  weeks += (yday % 7) > dow ? 2 : 1;
  return weeks;
}


x86 assembly (clang, -O0):
<week>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1122 <week+0x22>
mov    $0x7,%eax
mov    %eax,-0x18(%rbp)
jmp    112b <week+0x2b>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0xc(%rbp),%esi
mov    $0x1,%eax
mov    $0x2,%ecx
cmp    %esi,%edx
cmovg  %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<week>:
mov    (%rdi),%eax
test   %eax,%eax
mov    $0x7,%ecx
cmovne %eax,%ecx
mov    0x4(%rdi),%eax
mov    %eax,%edx
add    $0x1,%edx
movslq %edx,%rdx
imul   $0xffffffff92492493,%rdx,%rdx
shr    $0x20,%rdx
add    %eax,%edx
add    $0x1,%edx
mov    %edx,%esi
shr    $0x1f,%esi
sar    $0x2,%edx
add    %esi,%edx
lea    0x0(,%rdx,8),%esi
mov    %edx,%edi
sub    %esi,%edi
add    %edi,%eax
add    $0x1,%eax
xor    %esi,%esi
cmp    %ecx,%eax
setg   %sil
lea    (%rsi,%rdx,1),%eax
add    $0x1,%eax
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
define i32 @week(%struct.tm* %0) {
%2 = alloca %struct.tm*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.tm* %0, %struct.tm** %2
%6 = load %struct.tm*, %struct.tm** %2
%7 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
br label %15
11: ; preds = %1
%12 = load %struct.tm*, %struct.tm** %2
%13 = getelementptr inbounds %struct.tm, %struct.tm* %12, i32 0, i32 0
%14 = load i32, i32* %13
br label %15
15: ; preds = %11, %10
%16 = phi i32 [ 7, %10 ], [ %14, %11 ]
store i32 %16, i32* %3
%17 = load %struct.tm*, %struct.tm** %2
%18 = getelementptr inbounds %struct.tm, %struct.tm* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = sdiv i32 %21, 7
store i32 %22, i32* %4
%23 = load i32, i32* %5
%24 = srem i32 %23, 7
%25 = load i32, i32* %3
%26 = icmp sgt i32 %24, %25
%27 = zext i1 %26 to i64
%28 = select i1 %26, i32 2, i32 1
%29 = load i32, i32* %4
%30 = add nsw i32 %29, %28
store i32 %30, i32* %4
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
define i32 @week(%struct.tm* nocapture %0) {
%2 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 7, i32 %3
%6 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = add nsw i32 %7, 1
%9 = sdiv i32 %8, 7
%10 = srem i32 %8, 7
%11 = icmp sgt i32 %10, %5
%12 = select i1 %11, i32 2, i32 1
%13 = add nsw i32 %12, %9
ret i32 %13
}