#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_mday;
  int tm_wday;
};

/* Variables and functions */
int ac_get_mweek(struct tm *_tm) {
  if (!_tm)
    return -1;
  return ((_tm->tm_mday - 1) / 7 +
          (7 - (6 + _tm->tm_wday) % 7 + (_tm->tm_mday - 1) % 7) / 7);
}


x86 assembly (clang, -O0):
<ac_get_mweek>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    111f <ac_get_mweek+0x1f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1177 <ac_get_mweek+0x77>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
add    $0x6,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    $0x7,%eax
sub    %edx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%eax
add    %edx,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ac_get_mweek>:
test   %rdi,%rdi
je     118d <ac_get_mweek+0x8d>
mov    (%rdi),%eax
mov    0x4(%rdi),%edx
lea    -0x1(%rax),%esi
mov    %edx,%ecx
add    $0x6,%ecx
movslq %ecx,%r8
imul   $0xffffffff92492493,%r8,%rdi
shr    $0x20,%rdi
add    %edi,%edx
add    $0x6,%edx
mov    %edx,%edi
shr    $0x1f,%edi
sar    $0x2,%edx
add    %edi,%edx
lea    0x0(,%rdx,8),%edi
sub    %edx,%edi
movslq %esi,%rdx
imul   $0xffffffff92492493,%rdx,%rdx
shr    $0x20,%rdx
lea    (%rdx,%rax,1),%ecx
add    $0xffffffff,%ecx
mov    %ecx,%esi
shr    $0x1f,%esi
sar    $0x2,%ecx
add    %esi,%ecx
lea    0x0(,%rcx,8),%esi
mov    %ecx,%edx
sub    %esi,%edx
add    %edx,%eax
add    $0xffffffff,%eax
sub    %r8d,%edi
add    %edi,%eax
add    $0x7,%eax
movsbl %al,%edx
imul   $0xffffff93,%edx,%edx
shr    $0x8,%edx
add    %al,%dl
mov    %edx,%eax
shr    $0x7,%al
sar    $0x2,%dl
add    %al,%dl
movzbl %dl,%eax
add    %ecx,%eax
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32 }
define i32 @ac_get_mweek(%struct.tm* %0) {
%2 = alloca i32
%3 = alloca %struct.tm*
store %struct.tm* %0, %struct.tm** %3
%4 = load %struct.tm*, %struct.tm** %3
%5 = icmp ne %struct.tm* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i32 -1, i32* %2
br label %27
7: ; preds = %1
%8 = load %struct.tm*, %struct.tm** %3
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %10, 1
%12 = sdiv i32 %11, 7
%13 = load %struct.tm*, %struct.tm** %3
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 6, %15
%17 = srem i32 %16, 7
%18 = sub nsw i32 7, %17
%19 = load %struct.tm*, %struct.tm** %3
%20 = getelementptr inbounds %struct.tm, %struct.tm* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = sub nsw i32 %21, 1
%23 = srem i32 %22, 7
%24 = add nsw i32 %18, %23
%25 = sdiv i32 %24, 7
%26 = add nsw i32 %12, %25
store i32 %26, i32* %2
br label %27
27: ; preds = %7, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
define i32 @ac_get_mweek(%struct.tm* %0) {
%2 = icmp eq %struct.tm* %0, null
br i1 %2, label %19, label %3
3: ; preds = %1
%4 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = add nsw i32 %5, -1
%7 = sdiv i32 %6, 7
%8 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%9 = load i32, i32* %8
%10 = add nsw i32 %9, 6
%11 = srem i32 %10, 7
%12 = srem i32 %6, 7
%13 = add nsw i32 %12, 7
%14 = sub nsw i32 %13, %11
%15 = trunc i32 %14 to i8
%16 = sdiv i8 %15, 7
%17 = zext i8 %16 to i32
%18 = add nsw i32 %7, %17
br label %19
19: ; preds = %1, %3
%20 = phi i32 [ %18, %3 ], [ -1, %1 ]
ret i32 %20
}