#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 */

/* Variables and functions */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
void main() {
  int days;
  int ret;
  while (1) {
    int ret_getchar = 0;
    ret = scanf("%d", &days);
    if (ret == 1 && (ret_getchar = getchar()) == '\n' && days >= 0)
      break;
    printf("input invalid.\n");
    if (ret != 1 || ret_getchar != '\n')
      while (getchar() != '\n')
        ;
  }
  printf("week = %d, ", days / 7);
  printf("days = %d\n", days % 7);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1181 <main+0x51>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0xc(%rbp)
cmp    $0xa,%eax
jne    1181 <main+0x51>
cmpl   $0x0,-0x4(%rbp)
jl     1181 <main+0x51>
jmp    11ca <main+0x9a>
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11a3 <main+0x73>
cmpl   $0xa,-0xc(%rbp)
je     11c5 <main+0x95>
jmp    11a8 <main+0x78>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11c0 <main+0x90>
jmp    11a8 <main+0x78>
jmp    11c5 <main+0x95>
jmp    1138 <main+0x8>
mov    -0x4(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xead(%rip),%r14
lea    0xc(%rsp),%r15
lea    0xebb(%rip),%r12
nop
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <scanf@plt>
mov    %eax,%ebp
mov    $0x0,%ebx
cmp    $0x1,%eax
jne    118e <main+0x4e>
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ebx
cmp    $0xa,%bl
jne    118e <main+0x4e>
mov    0xc(%rsp),%esi
test   %esi,%esi
jns    11ad <main+0x6d>
mov    %r12,%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jne    11a0 <main+0x60>
cmp    $0xa,%ebx
je     1160 <main+0x20>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11a0 <main+0x60>
jmp    1160 <main+0x20>
mov    %esi,%eax
imul   $0x24924925,%rax,%rax
shr    $0x20,%rax
sub    %eax,%esi
shr    %esi
add    %eax,%esi
shr    $0x2,%esi
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movslq 0xc(%rsp),%rax
imul   $0xffffffff92492493,%rax,%rsi
shr    $0x20,%rsi
add    %eax,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
sar    $0x2,%esi
add    %ecx,%esi
lea    0x0(,%rsi,8),%ecx
sub    %ecx,%esi
add    %eax,%esi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [16 x i8] c"input invalid.\0A\00"
@.str.2 = [12 x i8] c"week = %d, \00"
@.str.3 = [11 x i8] c"days = %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
br label %4
4: ; preds = %0, %30
store i32 0, i32* %3
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %16
8: ; preds = %4
%9 = call signext i8 (...) @getchar()
%10 = sext i8 %9 to i32
store i32 %10, i32* %3
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* %1
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
br label %31
16: ; preds = %12, %8, %4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %2
%19 = icmp ne i32 %18, 1
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i32, i32* %3
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %30
23: ; preds = %20, %16
br label %24
24: ; preds = %28, %23
%25 = call signext i8 (...) @getchar()
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %24
br label %24
29: ; preds = %24
br label %30
30: ; preds = %29, %20
br label %4
31: ; preds = %15
%32 = load i32, i32* %1
%33 = sdiv i32 %32, 7
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %1
%36 = srem i32 %35, 7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.2 = [12 x i8] c"week = %d, \00"
@.str.3 = [11 x i8] c"days = %d\0A\00"
@str = [15 x i8] c"input invalid.\00"
define void @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %19, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = call signext i8 (...) @getchar()
%8 = sext i8 %7 to i32
%9 = icmp eq i8 %7, 10
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, -1
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %23, label %13
13: ; preds = %6, %3
%14 = phi i32 [ %8, %6 ], [ 0, %3 ]
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%16 = icmp ne i32 %4, 1
%17 = icmp ne i32 %14, 10
%18 = or i1 %16, %17
br i1 %18, label %20, label %19
19: ; preds = %20, %13
br label %3
20: ; preds = %13, %20
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
br i1 %22, label %19, label %20
23: ; preds = %6
%24 = udiv i32 %10, 7
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %1
%27 = srem i32 %26, 7
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %27)
ret void
}