#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 */
int /*<<< orphan*/ package_erase_one_day(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int write_buffer(int, char *, char *);
int clean_memmory_state(int tty, unsigned int days_in_log, int skip_days) {
  char buffer[17];
  int res;
  int pos = 0;
  unsigned int check = days_in_log;
  for (pos = 0; pos < 32; pos++) {
    if (check & 1) {
      if (pos > skip_days) {
        package_erase_one_day(buffer, pos);
        res = write_buffer(tty, buffer, buffer);
        if (res < 17) {
          printf("?? Can't clean up, package is too short\n");
          return res;
        } else {
          printf("cleaned up %d days back\n", pos);
        }
      }
    }
    check = check >> 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<clean_memmory_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
cmpl   $0x20,-0x38(%rbp)
jge    11ee <clean_memmory_state+0xbe>
mov    -0x3c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d7 <clean_memmory_state+0xa7>
mov    -0x38(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11d2 <clean_memmory_state+0xa2>
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%esi
call   1050 <package_erase_one_day@plt>
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1030 <write_buffer@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x11,-0x34(%rbp)
jge    11bc <clean_memmory_state+0x8c>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <clean_memmory_state+0xc5>
mov    -0x38(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d2 <clean_memmory_state+0xa2>
jmp    11d7 <clean_memmory_state+0xa7>
mov    -0x3c(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1155 <clean_memmory_state+0x25>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_memmory_state>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %edi,%r14d
mov    %rsp,%r13
xor    %ebx,%ebx
jmp    116a <clean_memmory_state+0x2a>
nopl   (%rax)
shr    %ebp
add    $0x1,%ebx
cmp    $0x20,%ebx
je     11a4 <clean_memmory_state+0x64>
test   $0x1,%bpl
je     1160 <clean_memmory_state+0x20>
cmp    %r15d,%ebx
jle    1160 <clean_memmory_state+0x20>
mov    %r13,%rdi
mov    %ebx,%esi
call   1060 <package_erase_one_day@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %r13,%rdx
call   1040 <write_buffer@plt>
cmp    $0x10,%eax
jle    11a9 <clean_memmory_state+0x69>
lea    0xe67(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1160 <clean_memmory_state+0x20>
xor    %r12d,%r12d
jmp    11b8 <clean_memmory_state+0x78>
mov    %eax,%r12d
lea    0xe66(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"?? Can't clean up, package is too short\0A\00"
@.str.1 = [25 x i8] c"cleaned up %d days back\0A\00"
define i32 @clean_memmory_state(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [17 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %10
%12 = load i32, i32* %6
store i32 %12, i32* %11
store i32 0, i32* %10
br label %13
13: ; preds = %45, %3
%14 = load i32, i32* %10
%15 = icmp slt i32 %14, 32
br i1 %15, label %16, label %48
16: ; preds = %13
%17 = load i32, i32* %11
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %42
20: ; preds = %16
%21 = load i32, i32* %10
%22 = load i32, i32* %7
%23 = icmp sgt i32 %21, %22
br i1 %23, label %24, label %41
24: ; preds = %20
%25 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* %10
%27 = call i32 @package_erase_one_day(i8* %25, i32 %26)
%28 = load i32, i32* %5
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%30 = getelementptr inbounds [17 x i8], [17 x i8]* %8, i64 0, i64 0
%31 = call i32 @write_buffer(i32 %28, i8* %29, i8* %30)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp slt i32 %32, 17
br i1 %33, label %34, label %37
34: ; preds = %24
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* %9
store i32 %36, i32* %4
br label %49
37: ; preds = %24
%38 = load i32, i32* %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %37
br label %41
41: ; preds = %40, %20
br label %42
42: ; preds = %41, %16
%43 = load i32, i32* %11
%44 = lshr i32 %43, 1
store i32 %44, i32* %11
br label %45
45: ; preds = %42
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %13
48: ; preds = %13
store i32 0, i32* %4
br label %49
49: ; preds = %48, %34
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"cleaned up %d days back\0A\00"
@str = [40 x i8] c"?? Can't clean up, package is too short\00"
define i32 @clean_memmory_state(i32 %0, i32 %1, i32 %2) {
%4 = alloca [17 x i8]
%5 = getelementptr inbounds [17 x i8], [17 x i8]* %4, i64 0, i64 0
br label %6
6: ; preds = %3, %21
%7 = phi i32 [ %1, %3 ], [ %22, %21 ]
%8 = phi i32 [ 0, %3 ], [ %23, %21 ]
%9 = and i32 %7, 1
%10 = icmp ne i32 %9, 0
%11 = icmp sgt i32 %8, %2
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %21
13: ; preds = %6
%14 = call i32 @package_erase_one_day(i8* %5, i32 %8)
%15 = call i32 @write_buffer(i32 %0, i8* %5, i8* %5)
%16 = icmp slt i32 %15, 17
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %25
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %21
21: ; preds = %19, %6
%22 = lshr i32 %7, 1
%23 = add nuw nsw i32 %8, 1
%24 = icmp eq i32 %23, 32
br i1 %24, label %25, label %6
25: ; preds = %21, %17
%26 = phi i32 [ %15, %17 ], [ 0, %21 ]
ret i32 %26
}