#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 dummy;
};

/* Variables and functions */
char *basename(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strptime(char *, char *, struct tm *);
scalar_t__ sync_time(char *, struct tm *);
int main(int argc, char **argv) {
  if (argc < 2) {
    printf("usage: %s <device> [time]\n", basename(argv[0]));
    return 1;
  }
  struct tm time;
  struct tm *ptime = NULL;
  if (argc > 2) {
    if (strptime(argv[2], "%Y-%m-%dT%H:%M:%S", &time)) {
      ptime = &time;
    } else {
      printf("Could not parse time. Using local time.\n");
      printf("Time string needs to use the format YYYY-MM-DDThh:mm:ss\n");
      printf("(ISO 8601 format)\n");
    }
  }
  if (sync_time(argv[1], ptime)) {
    printf("Error occured while syncing time.\n");
  } else {
    printf("Time was synced!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1189 <main+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <basename@plt>
mov    %rax,%rsi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xfc>
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11f9 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe71(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <strptime@plt>
cmp    $0x0,%rax
je     11ca <main+0x8a>
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11f4 <main+0xb4>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f9 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <sync_time@plt>
cmp    $0x0,%rax
je     1227 <main+0xe7>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <main+0xf5>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     1182 <main+0x32>
mov    (%rbx),%rdi
call   1050 <basename@plt>
lea    0xe90(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    11f4 <main+0xa4>
xor    %r14d,%r14d
cmp    $0x2,%edi
je     11cb <main+0x7b>
mov    0x10(%rbx),%rdi
lea    0xe86(%rip),%rsi
lea    0x8(%rsp),%r15
mov    %r15,%rdx
call   1070 <strptime@plt>
test   %rax,%rax
jne    11ce <main+0x7e>
lea    0xeb2(%rip),%rdi
call   1030 <puts@plt>
lea    0xece(%rip),%rdi
call   1030 <puts@plt>
lea    0xefa(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
mov    0x8(%rbx),%rdi
mov    %r15,%rsi
call   1060 <sync_time@plt>
test   %rax,%rax
lea    0xe49(%rip),%rax
lea    0xe53(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [27 x i8] c"usage: %s <device> [time]\0A\00"
@.str.1 = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@.str.2 = [41 x i8] c"Could not parse time. Using local time.\0A\00"
@.str.3 = [57 x i8] c"Time string needs to use the format YYYY-MM-DDThh:mm:ss\0A\00"
@.str.4 = [19 x i8] c"(ISO 8601 format)\0A\00"
@.str.5 = [35 x i8] c"Error occured while syncing time.\0A\00"
@.str.6 = [18 x i8] c"Time was synced!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tm
%7 = alloca %struct.tm*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i8* @basename(i8* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %43
16: ; preds = %2
store %struct.tm* null, %struct.tm** %7
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 2
br i1 %18, label %19, label %31
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i64 @strptime(i8* %22, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %6)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %19
store %struct.tm* %6, %struct.tm** %7
br label %30
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %26, %25
br label %31
31: ; preds = %30, %16
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = load %struct.tm*, %struct.tm** %7
%36 = call i64 @sync_time(i8* %34, %struct.tm* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %42
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %42
42: ; preds = %40, %38
store i32 0, i32* %3
br label %43
43: ; preds = %42, %10
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [27 x i8] c"usage: %s <device> [time]\0A\00"
@.str.1 = [18 x i8] c"%Y-%m-%dT%H:%M:%S\00"
@str = [17 x i8] c"Time was synced!\00"
@str.7 = [34 x i8] c"Error occured while syncing time.\00"
@str.8 = [40 x i8] c"Could not parse time. Using local time.\00"
@str.9 = [56 x i8] c"Time string needs to use the format YYYY-MM-DDThh:mm:ss\00"
@str.10 = [18 x i8] c"(ISO 8601 format)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.tm
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i8* @basename(i8* %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %29
9: ; preds = %2
%10 = bitcast %struct.tm* %3 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = call i64 @strptime(i8* %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), %struct.tm* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str.9, i64 0, i64 0))
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
br label %21
21: ; preds = %12, %17, %9
%22 = phi %struct.tm* [ null, %17 ], [ null, %9 ], [ %3, %12 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @sync_time(i8* %24, %struct.tm* %22)
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0)
%28 = call i32 @puts(i8* dereferenceable(1) %27)
br label %29
29: ; preds = %21, %5
%30 = phi i32 [ 1, %5 ], [ 0, %21 ]
ret i32 %30
}