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

/* Variables and functions */
int /*<<< orphan*/ mktime(struct tm *);
int /*<<< orphan*/ printf(char *);
scalar_t__ settimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ sscanf(char *, char *, scalar_t__ *, scalar_t__ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int System_SetTime(char *dt) {
  struct rtc_time tm;
  struct tm _tm;
  struct timeval tv;
  time_t timep;
  sscanf(dt, "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
         &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
  _tm.tm_sec = tm.tm_sec;
  _tm.tm_min = tm.tm_min;
  _tm.tm_hour = tm.tm_hour;
  _tm.tm_mday = tm.tm_mday;
  _tm.tm_mon = tm.tm_mon - 1;
  _tm.tm_year = tm.tm_year - 1900;
  timep = mktime(&_tm);
  tv.tv_sec = timep;
  tv.tv_usec = 0;
  if (settimeofday(&tv, (struct timezone *)0) < 0) {
    printf("Set system datetime error!\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<System_SetTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x30(%rbp),%rcx
add    $0x8,%rcx
lea    -0x30(%rbp),%r8
add    $0x10,%r8
lea    -0x30(%rbp),%r9
add    $0x14,%r9
lea    -0x30(%rbp),%r10
add    $0x18,%r10
lea    -0x30(%rbp),%rax
add    $0x1c,%rax
lea    0xe7a(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1050 <sscanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
sub    $0x76c,%rax
mov    %rax,-0x50(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <mktime@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <settimeofday@plt>
cmp    $0x0,%rax
jge    120f <System_SetTime+0xcf>
lea    0xe14(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <System_SetTime+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<System_SetTime>:
push   %rbx
sub    $0x50,%rsp
lea    0x8(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x14(%rsp),%r9
lea    0x18(%rsp),%rax
lea    0x1c(%rsp),%rbx
lea    0xeab(%rip),%rsi
mov    %rsp,%rdx
push   %rbx
push   %rax
call   1050 <sscanf@plt>
add    $0x10,%rsp
movdqa (%rsp),%xmm0
movaps 0x10(%rsp),%xmm1
movaps %xmm1,0x40(%rsp)
paddq  0xe76(%rip),%xmm0
movdqa %xmm0,0x30(%rsp)
lea    0x30(%rsp),%rdi
call   1060 <mktime@plt>
mov    %eax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
xor    %ebx,%ebx
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1040 <settimeofday@plt>
test   %rax,%rax
jns    11cb <System_SetTime+0x8b>
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.rtc_time = type { i64, i64, i32, i32, i32, i32 }
%struct.tm = type { i64, i64, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
@.str = [18 x i8] c"%d-%d-%d %d:%d:%d\00"
@.str.1 = [28 x i8] c"Set system datetime error!\0A\00"
define i32 @System_SetTime(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.rtc_time
%5 = alloca %struct.tm
%6 = alloca %struct.timeval
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 0
%10 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 1
%11 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 2
%12 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 3
%13 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 4
%14 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 5
%15 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64* %9, i64* %10, i32* %11, i32* %12, i32* %13, i32* %14)
%16 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 5
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 5
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 4
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 4
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 3
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 3
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 2
%26 = load i32, i32* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 2
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 1
%29 = load i64, i64* %28
%30 = sub nsw i64 %29, 1
%31 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 1
store i64 %30, i64* %31
%32 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %4, i32 0, i32 0
%33 = load i64, i64* %32
%34 = sub nsw i64 %33, 1900
%35 = getelementptr inbounds %struct.tm, %struct.tm* %5, i32 0, i32 0
store i64 %34, i64* %35
%36 = call i32 @mktime(%struct.tm* %5)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i64 0, i64* %39
%40 = call i64 @settimeofday(%struct.timeval* %6, %struct.timezone* null)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %1
%43 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %45
44: ; preds = %1
store i32 0, i32* %2
br label %45
45: ; preds = %44, %42
%46 = load i32, i32* %2
ret i32 %46
}

LLVM IR (-O2):
%struct.rtc_time = type { i64, i64, i32, i32, i32, i32 }
%struct.tm = type { i64, i64, i32, i32, i32, i32 }
%struct.timeval = type { i64, i32 }
%struct.timezone = type { i32 }
@.str = [18 x i8] c"%d-%d-%d %d:%d:%d\00"
@str = [27 x i8] c"Set system datetime error!\00"
define i32 @System_SetTime(i8* nocapture %0) {
%2 = alloca %struct.rtc_time
%3 = alloca %struct.tm
%4 = alloca %struct.timeval
%5 = bitcast %struct.rtc_time* %2 to i8*
%6 = bitcast %struct.tm* %3 to i8*
%7 = bitcast %struct.timeval* %4 to i8*
%8 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 0
%9 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 1
%10 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 2
%11 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 3
%12 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 4
%13 = getelementptr inbounds %struct.rtc_time, %struct.rtc_time* %2, i64 0, i32 5
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64* %8, i64* %9, i32* %10, i32* %11, i32* %12, i32* %13)
%15 = bitcast i32* %10 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 2
%18 = bitcast i32* %17 to <4 x i32>*
store <4 x i32> %16, <4 x i32>* %18
%19 = bitcast %struct.rtc_time* %2 to <2 x i64>*
%20 = load <2 x i64>, <2 x i64>* %19
%21 = add nsw <2 x i64> %20, <i64 -1900, i64 -1>
%22 = bitcast %struct.tm* %3 to <2 x i64>*
store <2 x i64> %21, <2 x i64>* %22
%23 = call i32 @mktime(%struct.tm* %3)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i64 0, i64* %25
%26 = call i64 @settimeofday(%struct.timeval* %4, %struct.timezone* null)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %1
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %1, %28
%31 = phi i32 [ -1, %28 ], [ 0, %1 ]
ret i32 %31
}