#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 grabYear(unsigned long encoding) {
  char buf[8192];
  char buf2[8192];
  unsigned long year;
  sprintf(buf, "%lu", encoding);
  strncpy(buf2, buf, 4);
  buf2[4] = '\0';
  sscanf(buf2, "%lu", &year);
  return year;
}


x86 assembly (clang, -O0):
<grabYear>:
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
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x400c(%rbp)
lea    -0x4010(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x4018(%rbp),%rdx
call   1040 <sscanf@plt>
mov    -0x4018(%rbp),%rax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabYear>:
push   %r15
push   %r14
push   %rbx
sub    $0x4010,%rsp
mov    %rdi,%rdx
lea    0xeba(%rip),%r14
lea    0x2010(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <sprintf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x14(%rsp)
lea    0x8(%rsp),%rdx
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <sscanf@plt>
mov    0x8(%rsp),%rax
add    $0x4010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lu\00"
define i64 @grabYear(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 = call i32 @strncpy(i8* %9, i8* %10, i32 4)
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 4
store i8 0, i8* %12
%13 = getelementptr inbounds [8192 x i8], [8192 x i8]* %4, i64 0, i64 0
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %5)
%15 = load i64, i64* %5
ret i64 %15
}

LLVM IR (-O2):
@.str = [4 x i8] c"%lu\00"
define i64 @grabYear(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 = call i32 @strncpy(i8* %6, i8* %5, i32 4)
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 4
store i8 0, i8* %10
%11 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %4)
%12 = load i64, i64* %4
ret i64 %12
}