#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*/ sprintf(char *, char *, unsigned long);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long *);
int /*<<< orphan*/ strncpy(char *, char *, int);
unsigned long grabDay(unsigned long encoding) {
  char buf[8192];
  char buf2[8192];
  unsigned long day;
  sprintf(buf, "%lu", encoding);
  strncpy(buf2, buf + 6, 2);
  buf2[2] = '\0';
  sscanf(buf2, "%lu", &day);
  return day;
}


x86 assembly (clang, -O0):
<grabDay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xeaf(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x4010(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
add    $0x6,%rsi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x400e(%rbp)
lea    -0x4010(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x4018(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x4018(%rbp),%rax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabDay>:
push   %r14
push   %rbx
sub    $0x4018,%rsp
mov    %rdi,%rdx
lea    0xebc(%rip),%r14
lea    0x2010(%rsp),%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x2016(%rsp),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x12(%rsp)
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <sscanf@plt>
mov    0x8(%rsp),%rax
add    $0x4018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lu\00"
define i64 @grabDay(i64 %0) {
%2 = alloca i64
%3 = alloca [8192 x i8]
%4 = alloca [8192 x i8]
%5 = alloca i64
store i64 %0, i64* %2
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%7 = load i64, i64* %2
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds i8, i8* %10, i64 6
%12 = call i32 @strncpy(i8* %9, i8* %11, i32 2)
%13 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 2
store i8 0, i8* %13
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %5)
%16 = load i64, i64* %5
ret i64 %16
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lu\00"
define i64 @grabDay(i64 %0) {
%2 = alloca [8192 x i8]
%3 = alloca [8192 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%7 = bitcast i64* %4 to i8*
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 %0)
%9 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 6
%10 = call i32 @strncpy(i8* %6, i8* %9, i32 2)
%11 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 2
store i8 0, i8* %11
%12 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %4)
%13 = load i64, i64* %4
ret i64 %13
}