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

/* Variables and functions */
int ac_get_yweek(struct tm *_tm) {
  int week = -1;
  if (!_tm)
    return -1;
  week =
      (int)(((_tm)->tm_yday + 7 - ((_tm)->tm_wday ? (_tm)->tm_wday - 1 : 6)) /
            7);
  return week;
}


x86 assembly (clang, -O0):
<ac_get_yweek>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1126 <ac_get_yweek+0x26>
movl   $0xffffffff,-0x4(%rbp)
jmp    1178 <ac_get_yweek+0x78>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x7,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,0x4(%rax)
je     1152 <ac_get_yweek+0x52>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <ac_get_yweek+0x5f>
mov    $0x6,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <ac_get_yweek+0x5f>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    %ecx,%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ac_get_yweek>:
test   %rdi,%rdi
je     1141 <ac_get_yweek+0x41>
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
mov    $0x1,%edx
sub    %ecx,%edx
test   %ecx,%ecx
mov    $0xfffffffa,%ecx
cmovne %edx,%ecx
lea    (%rax,%rcx,1),%edx
add    $0x7,%edx
add    %ecx,%eax
movslq %edx,%rcx
imul   $0xffffffff92492493,%rcx,%rcx
shr    $0x20,%rcx
add    %ecx,%eax
add    $0x7,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x2,%eax
add    %ecx,%eax
ret
mov    $0xffffffff,%eax
ret

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

LLVM IR (-O2):
%struct.tm = type { i32, i32 }
define i32 @ac_get_yweek(%struct.tm* %0) {
%2 = icmp eq %struct.tm* %0, null
br i1 %2, label %14, 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, 7
%7 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
%10 = sub i32 1, %8
%11 = select i1 %9, i32 -6, i32 %10
%12 = add i32 %6, %11
%13 = sdiv i32 %12, 7
br label %14
14: ; preds = %1, %3
%15 = phi i32 [ %13, %3 ], [ -1, %1 ]
ret i32 %15
}