#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 */
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
char *strptime(char *, char *, struct tm *);
int nmea_time_parse(char *s, struct tm *time) {
  char *rv;
  memset(time, 0, sizeof(struct tm));
  if (s == NULL || *s == '\0') {
    return -1;
  }
  rv = strptime(s, "%H%M%S", time);
  if (NULL == rv || (int)(rv - s) != 6) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<nmea_time_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     115b <nmea_time_parse+0x3b>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1167 <nmea_time_parse+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <nmea_time_parse+0x92>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8a(%rip),%rsi
call   1040 <strptime@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x20(%rbp),%rax
je     119f <nmea_time_parse+0x7f>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x6,%eax
je     11ab <nmea_time_parse+0x8b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <nmea_time_parse+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_time_parse>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    $0xffffffff,%eax
test   %rbx,%rbx
je     116f <nmea_time_parse+0x4f>
cmpb   $0x0,(%rbx)
je     116f <nmea_time_parse+0x4f>
lea    0xeb1(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <strptime@plt>
test   %rax,%rax
sete   %cl
sub    %ebx,%eax
cmp    $0x6,%eax
setne  %al
or     %cl,%al
movzbl %al,%eax
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%H%M%S\00"
define i32 @nmea_time_parse(i8* %0, %struct.tm* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.tm*
%6 = alloca i8*
store i8* %0, i8** %4
store %struct.tm* %1, %struct.tm** %5
%7 = load %struct.tm*, %struct.tm** %5
%8 = call i32 @memset(%struct.tm* %7, i32 0, i32 4)
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11, %2
store i32 -1, i32* %3
br label %33
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = load %struct.tm*, %struct.tm** %5
%20 = call i8* @strptime(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %19)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = icmp eq i8* null, %21
br i1 %22, label %31, label %23
23: ; preds = %17
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = icmp ne i32 %29, 6
br i1 %30, label %31, label %32
31: ; preds = %23, %17
store i32 -1, i32* %3
br label %33
32: ; preds = %23
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31, %16
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"%H%M%S\00"
define i32 @nmea_time_parse(i8* %0, %struct.tm* %1) {
%3 = tail call i32 @memset(%struct.tm* %1, i32 0, i32 4)
%4 = icmp eq i8* %0, null
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %5
%9 = tail call i8* @strptime(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %struct.tm* %1)
%10 = icmp eq i8* %9, null
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %0 to i64
%13 = sub i64 %11, %12
%14 = trunc i64 %13 to i32
%15 = icmp ne i32 %14, 6
%16 = select i1 %10, i1 true, i1 %15
%17 = sext i1 %16 to i32
br label %18
18: ; preds = %8, %2, %5
%19 = phi i32 [ -1, %5 ], [ -1, %2 ], [ %17, %8 ]
ret i32 %19
}