#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 *);
int main(void) {
  int days;
  printf("how many days do you wanna calculater: ");
  int ret1, ret2;
  while ((ret1 = scanf("%d", &days)) != 1 || days < 0 ||
         (ret2 = getchar()) != '\n') {
    if (ret1 != 1 || ret2 != '\n')
      while (getchar() != '\n')
        ;
    printf("input invalid!\n");
    printf("how many days do you wanna calculater: ");
  }
  printf("%d days are %d weeks, %d days\n", days, days / 7, days % 7);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed4(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
mov    $0x1,%al
cmp    $0x1,%ecx
mov    %al,-0x11(%rbp)
jne    1195 <main+0x65>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
jl     1195 <main+0x65>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
mov    %eax,-0x10(%rbp)
cmp    $0xa,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    11a5 <main+0x75>
jmp    11fc <main+0xcc>
cmpl   $0x1,-0xc(%rbp)
jne    11b9 <main+0x89>
cmpl   $0xa,-0x10(%rbp)
je     11db <main+0xab>
jmp    11be <main+0x8e>
mov    $0x0,%al
call   1040 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11d6 <main+0xa6>
jmp    11be <main+0x8e>
jmp    11db <main+0xab>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    114d <main+0x1d>
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x7,%ecx
cltd
idiv   %ecx
mov    %edx,%ecx
mov    -0x18(%rbp),%edx
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeae(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec5(%rip),%r15
lea    0x4(%rsp),%r13
lea    0xedb(%rip),%r12
jmp    1192 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    11b9 <main+0x79>
cmpl   $0x0,0x4(%rsp)
js     11b9 <main+0x79>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11dd <main+0x9d>
movsbl %al,%ebx
cmp    $0x1,%ebp
jne    11d0 <main+0x90>
cmp    $0xa,%ebx
je     1180 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
jne    11d0 <main+0x90>
jmp    1180 <main+0x40>
movslq 0x4(%rsp),%rsi
imul   $0xffffffff92492493,%rsi,%rdx
shr    $0x20,%rdx
add    %esi,%edx
mov    %edx,%eax
shr    $0x1f,%eax
sar    $0x2,%edx
add    %eax,%edx
lea    0x0(,%rdx,8),%eax
mov    %edx,%ecx
sub    %eax,%ecx
add    %esi,%ecx
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [40 x i8] c"how many days do you wanna calculater: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.3 = [31 x i8] c"%d days are %d weeks, %d days\0A\00"
@str = [15 x i8] c"input invalid!\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %22, %0
%5 = phi i32 [ undef, %0 ], [ %16, %22 ]
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = icmp ne i32 %6, 1
%8 = load i32, i32* %1
%9 = icmp slt i32 %8, 0
%10 = select i1 %7, i1 true, i1 %9
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = call signext i8 (...) @getchar()
%13 = sext i8 %12 to i32
%14 = icmp eq i8 %12, 10
br i1 %14, label %25, label %15
15: ; preds = %4, %11
%16 = phi i32 [ %5, %4 ], [ %13, %11 ]
%17 = icmp ne i32 %16, 10
%18 = select i1 %7, i1 true, i1 %17
br i1 %18, label %19, label %22
19: ; preds = %15, %19
%20 = call signext i8 (...) @getchar()
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %19
22: ; preds = %19, %15
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %4
25: ; preds = %11
%26 = load i32, i32* %1
%27 = sdiv i32 %26, 7
%28 = srem i32 %26, 7
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
ret i32 0
}