#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 */
struct tm {
  int tm_year;
  int tm_mon;
  int tm_hour;
  int tm_min;
  int /*<<< orphan*/ tm_sec;
  int /*<<< orphan*/ tm_mday;
};
struct timeval {
  scalar_t__ tv_usec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ settimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ systohw();
void settime(char *date, char *time) {
  struct timeval new_tv;
  struct tm new;
  sscanf(date, "%04d-%02d-%02d", &new.tm_year, &new.tm_mon, &new.tm_mday);
  sscanf(time, "%02d:%02d:%02d", &new.tm_hour, &new.tm_min, &new.tm_sec);
  new.tm_year -= 1900;
  new.tm_mon -= 1;
  new_tv.tv_sec = mktime(&new);
  new_tv.tv_usec = 0;
  settimeofday(&new_tv, NULL);
  systohw();
}


x86 assembly (clang, -O0):
<settime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x38(%rbp),%rdx
lea    -0x38(%rbp),%rcx
add    $0x4,%rcx
lea    -0x38(%rbp),%r8
add    $0x14,%r8
lea    0xe91(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x38(%rbp),%rdx
add    $0x8,%rdx
lea    -0x38(%rbp),%rcx
add    $0xc,%rcx
lea    -0x38(%rbp),%r8
add    $0x10,%r8
lea    0xe78(%rip),%rsi
call   1050 <sscanf@plt>
mov    -0x38(%rbp),%eax
sub    $0x76c,%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <settimeofday@plt>
mov    $0x0,%al
call   1030 <systohw@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<settime>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
lea    0x4(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0xea5(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdx
call   1050 <sscanf@plt>
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <sscanf@plt>
addl   $0xfffff894,(%rsp)
addl   $0xffffffff,0x4(%rsp)
mov    %r14,%rdi
call   1060 <mktime@plt>
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1040 <settimeofday@plt>
xor    %eax,%eax
call   1030 <systohw@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"%04d-%02d-%02d\00"
@.str.1 = [15 x i8] c"%02d:%02d:%02d\00"
define void @settime(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.timeval
%6 = alloca %struct.tm
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%9 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%10 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
%11 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i32* %10)
%12 = load i8*, i8** %4
%13 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%14 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
%15 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
%16 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %13, i32* %14, i32* %15)
%17 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sub nsw i32 %18, 1900
store i32 %19, i32* %17
%20 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %20
%23 = call i32 @mktime(%struct.tm* %6)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 0, i64* %25
%26 = call i32 @settimeofday(%struct.timeval* %5, i32* null)
%27 = call i32 (...) @systohw()
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@.str = [15 x i8] c"%04d-%02d-%02d\00"
@.str.1 = [15 x i8] c"%02d:%02d:%02d\00"
define void @settime(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.tm
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.tm* %4 to i8*
%7 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%8 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%9 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%10 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %7, i32* %8, i32* %9)
%11 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%12 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%13 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%14 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32* %11, i32* %12, i32* %13)
%15 = load i32, i32* %7
%16 = add nsw i32 %15, -1900
store i32 %16, i32* %7
%17 = load i32, i32* %8
%18 = add nsw i32 %17, -1
store i32 %18, i32* %8
%19 = call i32 @mktime(%struct.tm* %4)
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i64 0, i64* %21
%22 = call i32 @settimeofday(%struct.timeval* %3, i32* null)
%23 = call i32 (...) @systohw()
ret void
}