#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_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
scalar_t__ errno;
struct tm *localtime(int /*<<< orphan*/ *);
int sscanf(char const *, char *, unsigned int *, unsigned int *);
int /*<<< orphan*/ strcmp(char const *, char *);
int strtol(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int parse_when(const char *when) {
  unsigned hour, min;
  if (!strcmp(when, "now"))
    return 0;
  else if (when[0] == '+') {
    errno = 0;
    int s = strtol(++when, NULL, 10) * 60;
    if (!errno)
      return s;
  } else if (sscanf(when, "%u:%u", &hour, &min) == 2) {
    if (hour < 24 && min < 60) {
      time_t t = time(NULL);
      struct tm *tm = localtime(&t);
      int then = hour * 3600 + min * 60;
      int now = tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec;
      return then - now + 60 * 60 * 24 * (now > then);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_when>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1181 <parse_when+0x31>
movl   $0x0,-0x4(%rbp)
jmp    1297 <parse_when+0x147>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11e0 <parse_when+0x90>
mov    0x2e48(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
imul   $0x3c,%eax,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e1a(%rip),%rax
cmpq   $0x0,(%rax)
jne    11db <parse_when+0x8b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <parse_when+0x147>
jmp    128b <parse_when+0x13b>
mov    -0x10(%rbp),%rdi
lea    0xe19(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    1286 <parse_when+0x136>
cmpl   $0x18,-0x14(%rbp)
jae    1281 <parse_when+0x131>
cmpl   $0x3c,-0x18(%rbp)
jae    1281 <parse_when+0x131>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <localtime@plt>
mov    %rax,-0x28(%rbp)
imul   $0xe10,-0x14(%rbp),%eax
imul   $0x3c,-0x18(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
imul   $0xe10,(%rax),%eax
mov    -0x28(%rbp),%rcx
imul   $0x3c,0x4(%rcx),%ecx
add    %ecx,%eax
mov    -0x28(%rbp),%rcx
add    0x8(%rcx),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    -0x30(%rbp),%ecx
cmp    -0x2c(%rbp),%ecx
setg   %cl
and    $0x1,%cl
movzbl %cl,%ecx
imul   $0x15180,%ecx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1297 <parse_when+0x147>
jmp    1286 <parse_when+0x136>
jmp    128b <parse_when+0x13b>
jmp    1290 <parse_when+0x140>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_when>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     119b <parse_when+0x4b>
cmpb   $0x2b,(%rbx)
jne    119f <parse_when+0x4f>
mov    0x2e6a(%rip),%r14
movq   $0x0,(%r14)
add    $0x1,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
cmpq   $0x0,(%r14)
jne    1212 <parse_when+0xc2>
imul   $0x3c,%eax,%eax
jmp    1217 <parse_when+0xc7>
xor    %eax,%eax
jmp    1217 <parse_when+0xc7>
lea    0xe5e(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    1212 <parse_when+0xc2>
cmpl   $0x17,0x10(%rsp)
ja     1212 <parse_when+0xc2>
cmpl   $0x3b,0xc(%rsp)
ja     1212 <parse_when+0xc2>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rdi
call   1030 <localtime@plt>
imul   $0xe10,0x10(%rsp),%edx
mov    %rax,%rcx
imul   $0x3c,0xc(%rsp),%eax
add    %edx,%eax
imul   $0xe10,(%rcx),%edx
imul   $0x3c,0x4(%rcx),%esi
add    %edx,%esi
add    0x8(%rcx),%esi
mov    %eax,%ecx
sub    %esi,%ecx
add    $0x15180,%ecx
sub    %esi,%eax
cmovl  %ecx,%eax
jmp    1217 <parse_when+0xc7>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32 }
@.str = [4 x i8] c"now\00"
@errno = global i64 0
@.str.1 = [6 x i8] c"%u:%u\00"
define i32 @parse_when(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tm*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 0, i32* %2
br label %75
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 43
br i1 %20, label %21, label %31
21: ; preds = %15
store i64 0, i64* @errno
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %3
%24 = call i32 @strtol(i8* %23, i32* null, i32 10)
%25 = mul nsw i32 %24, 60
store i32 %25, i32* %6
%26 = load i64, i64* @errno
%27 = icmp ne i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %21
%29 = load i32, i32* %6
store i32 %29, i32* %2
br label %75
30: ; preds = %21
br label %73
31: ; preds = %15
%32 = load i8*, i8** %3
%33 = call i32 @sscanf(i8* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%34 = icmp eq i32 %33, 2
br i1 %34, label %35, label %72
35: ; preds = %31
%36 = load i32, i32* %4
%37 = icmp ult i32 %36, 24
br i1 %37, label %38, label %71
38: ; preds = %35
%39 = load i32, i32* %5
%40 = icmp ult i32 %39, 60
br i1 %40, label %41, label %71
41: ; preds = %38
%42 = call i32 @time(i32* null)
store i32 %42, i32* %7
%43 = call %struct.tm* @localtime(i32* %7)
store %struct.tm* %43, %struct.tm** %8
%44 = load i32, i32* %4
%45 = mul i32 %44, 3600
%46 = load i32, i32* %5
%47 = mul i32 %46, 60
%48 = add i32 %45, %47
store i32 %48, i32* %9
%49 = load %struct.tm*, %struct.tm** %8
%50 = getelementptr inbounds %struct.tm, %struct.tm* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = mul nsw i32 %51, 3600
%53 = load %struct.tm*, %struct.tm** %8
%54 = getelementptr inbounds %struct.tm, %struct.tm* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 60
%57 = add nsw i32 %52, %56
%58 = load %struct.tm*, %struct.tm** %8
%59 = getelementptr inbounds %struct.tm, %struct.tm* %58, i32 0, i32 2
%60 = load i32, i32* %59
%61 = add nsw i32 %57, %60
store i32 %61, i32* %10
%62 = load i32, i32* %9
%63 = load i32, i32* %10
%64 = sub nsw i32 %62, %63
%65 = load i32, i32* %10
%66 = load i32, i32* %9
%67 = icmp sgt i32 %65, %66
%68 = zext i1 %67 to i32
%69 = mul nsw i32 86400, %68
%70 = add nsw i32 %64, %69
store i32 %70, i32* %2
br label %75
71: ; preds = %38, %35
br label %72
72: ; preds = %71, %31
br label %73
73: ; preds = %72, %30
br label %74
74: ; preds = %73
store i32 -1, i32* %2
br label %75
75: ; preds = %74, %41, %28, %14
%76 = load i32, i32* %2
ret i32 %76
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32 }
@.str = [4 x i8] c"now\00"
@errno = global i64 0
@.str.1 = [6 x i8] c"%u:%u\00"
define i32 @parse_when(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %51, label %9
9: ; preds = %1
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 43
br i1 %11, label %12, label %18
12: ; preds = %9
store i64 0, i64* @errno
%13 = getelementptr inbounds i8, i8* %0, i64 1
%14 = tail call i32 @strtol(i8* nocapture %13, i32* null, i32 10)
%15 = mul nsw i32 %14, 60
%16 = load i64, i64* @errno
%17 = icmp eq i64 %16, 0
br i1 %17, label %51, label %50
18: ; preds = %9
%19 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %2, i32* %3)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %50
21: ; preds = %18
%22 = load i32, i32* %2
%23 = icmp ult i32 %22, 24
%24 = load i32, i32* %3
%25 = icmp ult i32 %24, 60
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %27, label %50
27: ; preds = %21
%28 = bitcast i32* %4 to i8*
%29 = call i32 @time(i32* null)
store i32 %29, i32* %4
%30 = call %struct.tm* @localtime(i32* %4)
%31 = load i32, i32* %2
%32 = mul i32 %31, 3600
%33 = load i32, i32* %3
%34 = mul i32 %33, 60
%35 = add i32 %34, %32
%36 = getelementptr inbounds %struct.tm, %struct.tm* %30, i64 0, i32 0
%37 = load i32, i32* %36
%38 = mul nsw i32 %37, 3600
%39 = getelementptr inbounds %struct.tm, %struct.tm* %30, i64 0, i32 1
%40 = load i32, i32* %39
%41 = mul nsw i32 %40, 60
%42 = add nsw i32 %41, %38
%43 = getelementptr inbounds %struct.tm, %struct.tm* %30, i64 0, i32 2
%44 = load i32, i32* %43
%45 = add nsw i32 %42, %44
%46 = sub i32 %35, %45
%47 = icmp slt i32 %35, %45
%48 = select i1 %47, i32 86400, i32 0
%49 = add nsw i32 %46, %48
br label %51
50: ; preds = %12, %21, %18
br label %51
51: ; preds = %1, %12, %50, %27
%52 = phi i32 [ -1, %50 ], [ %15, %12 ], [ %49, %27 ], [ 0, %1 ]
ret i32 %52
}