#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
struct tm *gmtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int newdate(int oldd, int days) {
  int ano, mes, dia;
  time_t tt;
  struct tm date = {0};
  char snewd[9];
  ano = oldd / 10000;
  oldd -= ano * 10000;
  mes = oldd / 100;
  oldd -= mes * 100;
  dia = oldd;
  date.tm_year = ano - 1900;
  date.tm_mon = mes - 1;
  date.tm_mday = dia + days;
  tt = mktime(&date);
  date = *gmtime(&tt);
  sprintf(snewd, "%04d%02d%02d", date.tm_year + 1900, date.tm_mon + 1,
          date.tm_mday);
  oldd = (int)strtol(snewd, NULL, 10);
  return oldd;
}


x86 assembly (clang, -O0):
<newdate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%eax
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
imul   $0x2710,-0xc(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0x64,-0x10(%rbp),%ecx
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x14(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1050 <mktime@plt>
mov    %eax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <gmtime@plt>
mov    (%rax),%rcx
mov    %rcx,-0x28(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
lea    -0x31(%rbp),%rdi
mov    -0x28(%rbp),%edx
add    $0x76c,%edx
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    -0x20(%rbp),%r8d
lea    0xdf6(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x31(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<newdate>:
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0xc(%rsp)
movslq %edi,%rax
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%r8
shr    $0x3f,%r8
sar    $0x2c,%rcx
lea    (%rcx,%r8,1),%edi
imul   $0xffffd8f0,%edi,%edi
add    %edi,%eax
cltq
imul   $0x51eb851f,%rax,%rdi
mov    %rdi,%rbx
shr    $0x3f,%rbx
sar    $0x25,%rdi
lea    (%rdi,%rbx,1),%edx
imul   $0xffffff9c,%edx,%edx
add    %r8d,%ecx
add    $0xfffff894,%ecx
mov    %ecx,(%rsp)
lea    (%rdi,%rbx,1),%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x4(%rsp)
add    %esi,%eax
add    %edx,%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rdi
call   1040 <mktime@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rdi
call   1050 <gmtime@plt>
movups (%rax),%xmm0
movaps %xmm0,(%rsp)
mov    $0x76c,%edx
add    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
add    $0x1,%ecx
lea    0xe22(%rip),%rsi
lea    0x17(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <strtol@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32 }
@.str = [13 x i8] c"%04d%02d%02d\00"
define i32 @newdate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.tm
%10 = alloca [9 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%11 = bitcast %struct.tm* %9 to i8*
%12 = load i32, i32* %3
%13 = sdiv i32 %12, 10000
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 10000
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, %15
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = sdiv i32 %18, 100
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = mul nsw i32 %20, 100
%22 = load i32, i32* %3
%23 = sub nsw i32 %22, %21
store i32 %23, i32* %3
%24 = load i32, i32* %3
store i32 %24, i32* %7
%25 = load i32, i32* %5
%26 = sub nsw i32 %25, 1900
%27 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* %6
%29 = sub nsw i32 %28, 1
%30 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* %7
%32 = load i32, i32* %4
%33 = add nsw i32 %31, %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
store i32 %33, i32* %34
%35 = call i32 @mktime(%struct.tm* %9)
store i32 %35, i32* %8
%36 = call %struct.tm* @gmtime(i32* %8)
%37 = bitcast %struct.tm* %9 to i8*
%38 = bitcast %struct.tm* %36 to i8*
%39 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%40 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 0
%41 = load i32, i32* %40
%42 = add nsw i32 %41, 1900
%43 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 1
%44 = load i32, i32* %43
%45 = add nsw i32 %44, 1
%46 = getelementptr inbounds %struct.tm, %struct.tm* %9, i32 0, i32 2
%47 = load i32, i32* %46
%48 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %45, i32 %47)
%49 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%50 = call i64 @strtol(i8* %49, i32* null, i32 10)
%51 = trunc i64 %50 to i32
store i32 %51, i32* %3
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32 }
@.str = [13 x i8] c"%04d%02d%02d\00"
define i32 @newdate(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca [9 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.tm* %4 to i8*
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
store i32 0, i32* %8
%9 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%10 = sdiv i32 %0, 10000
%11 = mul nsw i32 %10, -10000
%12 = add i32 %11, %0
%13 = sdiv i32 %12, 100
%14 = mul nsw i32 %13, -100
%15 = add nsw i32 %10, -1900
%16 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
store i32 %15, i32* %16
%17 = add nsw i32 %13, -1
%18 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
store i32 %17, i32* %18
%19 = add i32 %12, %1
%20 = add i32 %19, %14
%21 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @mktime(%struct.tm* %4)
store i32 %22, i32* %3
%23 = call %struct.tm* @gmtime(i32* %3)
%24 = bitcast %struct.tm* %23 to i8*
%25 = load i32, i32* %16
%26 = add nsw i32 %25, 1900
%27 = load i32, i32* %18
%28 = add nsw i32 %27, 1
%29 = load i32, i32* %21
%30 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28, i32 %29)
%31 = call i64 @strtol(i8* nocapture %9, i32* null, i32 10)
%32 = trunc i64 %31 to i32
ret i32 %32
}