#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 time_t;
struct tm {
  scalar_t__ tm_gmtoff;
  int /*<<< orphan*/ tm_sec;
};

/* Variables and functions */
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
char *get_utc_timestamp(int);
int /*<<< orphan*/ memset(struct tm *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(scalar_t__);
char *strptime(char *, char *, struct tm *);
int timegm(struct tm *);
scalar_t__ timestamp_is_valid(char *);
int main(int argc, char *argv[]) {
  struct tm tm;
  char *remnant, *ts;
  time_t time;
  if (argc != 2) {
    printf("Usage: ./%s <timestamp string in ISO_8601 format>\n", argv[0]);
    return -1;
  }
  if (timestamp_is_valid(argv[1]) == 0) {
    printf("Provided timestamp is invalid, all or part of it will "
           "be ignored: %s\n",
           argv[1]);
  }
  memset(&tm, 0, sizeof(struct tm));
  errno = 0;
  remnant = strptime(argv[1], "%FT%T%z", &tm);
  printf("Input timestamp: %s, remnant: %s, errno: %s\n", argv[1], remnant,
         strerror(errno));
  tm.tm_sec -= tm.tm_gmtoff;
  tm.tm_gmtoff = 0;
  if ((time = timegm(&tm)) == -1) {
    printf("Failed to convert broken-down struct tm to time_t\n");
    return -1;
  }
  printf("Calender time in UTC (GMT+0) timezone: %ld\n", time);
  if (!(ts = get_utc_timestamp(time))) {
    printf("Failed to convert calender time to timestamp string\n");
    return -1;
  }
  printf("New timestamp: %s\n\n", ts);
  free(ts);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <timestamp_is_valid@plt>
cmp    $0x0,%rax
jne    11ee <main+0x6e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    0x2ddb(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1090 <strptime@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rcx
movslq -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <timegm@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
jne    12a9 <main+0x129>
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x34(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   10a0 <get_utc_timestamp@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12ea <main+0x16a>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <main+0x18c>
mov    -0x30(%rbp),%rsi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    127d <main+0xed>
mov    0x8(%rbx),%rdi
call   1080 <timestamp_is_valid@plt>
test   %rax,%rax
jne    11c6 <main+0x36>
mov    0x8(%rbx),%rsi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
mov    0x2dff(%rip),%r15
movq   $0x0,(%r15)
mov    0x8(%rbx),%rdi
lea    0xe86(%rip),%rsi
mov    %r14,%rdx
call   10a0 <strptime@plt>
mov    %rax,%rbp
mov    0x8(%rbx),%rbx
mov    (%r15),%rdi
call   1090 <strerror@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%eax
sub    %eax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %r14,%rdi
call   1070 <timegm@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0x100>
mov    %eax,%ebp
lea    0xe66(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
call   10b0 <get_utc_timestamp@plt>
test   %rax,%rax
je     1299 <main+0x109>
mov    %rax,%rbp
lea    0xe71(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    12aa <main+0x11a>
mov    (%rbx),%rsi
lea    0xd79(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12a5 <main+0x115>
lea    0xe8b(%rip),%rdi
jmp    12a0 <main+0x110>
lea    0xe4e(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i64, i32 }
@.str = [51 x i8] c"Usage: ./%s <timestamp string in ISO_8601 format>\0A\00"
@.str.1 = [70 x i8] c"Provided timestamp is invalid, all or part of it will be ignored: %s\0A\00"
@errno = global i64 0
@.str.2 = [8 x i8] c"%FT%T%z\00"
@.str.3 = [45 x i8] c"Input timestamp: %s, remnant: %s, errno: %s\0A\00"
@.str.4 = [51 x i8] c"Failed to convert broken-down struct tm to time_t\0A\00"
@.str.5 = [44 x i8] c"Calender time in UTC (GMT+0) timezone: %ld\0A\00"
@.str.6 = [53 x i8] c"Failed to convert calender time to timestamp string\0A\00"
@.str.7 = [20 x i8] c"New timestamp: %s\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.tm
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 -1, i32* %3
br label %66
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @timestamp_is_valid(i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %23, %17
%29 = call i32 @memset(%struct.tm* %6, i32 0, i32 16)
store i64 0, i64* @errno
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i8* @strptime(i8* %32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %6)
store i8* %33, i8** %7
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i8*, i8** %7
%38 = load i64, i64* @errno
%39 = call i8* @strerror(i64 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %36, i8* %37, i8* %39)
%41 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = sub nsw i64 %45, %42
%47 = trunc i64 %46 to i32
store i32 %47, i32* %43
%48 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
store i64 0, i64* %48
%49 = call i32 @timegm(%struct.tm* %6)
store i32 %49, i32* %9
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %28
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
53: ; preds = %28
%54 = load i32, i32* %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = load i32, i32* %9
%57 = call i8* @get_utc_timestamp(i32 %56)
store i8* %57, i8** %8
%58 = icmp ne i8* %57, null
br i1 %58, label %61, label %59
59: ; preds = %53
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %66
61: ; preds = %53
%62 = load i8*, i8** %8
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %62)
%64 = load i8*, i8** %8
%65 = call i32 @free(i8* %64)
store i32 0, i32* %3
br label %66
66: ; preds = %61, %59, %51, %12
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.tm = type { i64, i32 }
@.str = [51 x i8] c"Usage: ./%s <timestamp string in ISO_8601 format>\0A\00"
@.str.1 = [70 x i8] c"Provided timestamp is invalid, all or part of it will be ignored: %s\0A\00"
@errno = global i64 0
@.str.2 = [8 x i8] c"%FT%T%z\00"
@.str.3 = [45 x i8] c"Input timestamp: %s, remnant: %s, errno: %s\0A\00"
@.str.5 = [44 x i8] c"Calender time in UTC (GMT+0) timezone: %ld\0A\00"
@.str.7 = [20 x i8] c"New timestamp: %s\0A\0A\00"
@str = [52 x i8] c"Failed to convert calender time to timestamp string\00"
@str.8 = [50 x i8] c"Failed to convert broken-down struct tm to time_t\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.tm
%4 = bitcast %struct.tm* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %44
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @timestamp_is_valid(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %9
%18 = call i32 @memset(%struct.tm* %3, i32 0, i32 16)
store i64 0, i64* @errno
%19 = load i8*, i8** %10
%20 = call i8* @strptime(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %struct.tm* %3)
%21 = load i8*, i8** %10
%22 = load i64, i64* @errno
%23 = call i8* @strerror(i64 %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i8* %21, i8* %20, i8* %23)
%25 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.tm, %struct.tm* %3, i64 0, i32 1
%28 = load i32, i32* %27
%29 = trunc i64 %26 to i32
%30 = sub i32 %28, %29
store i32 %30, i32* %27
store i64 0, i64* %25
%31 = call i32 @timegm(%struct.tm* %3)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %17
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.8, i64 0, i64 0))
br label %44
35: ; preds = %17
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%37 = call i8* @get_utc_timestamp(i32 %31)
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
br label %44
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%43 = call i32 @free(i8* %37)
br label %44
44: ; preds = %41, %39, %33, %6
%45 = phi i32 [ -1, %6 ], [ -1, %33 ], [ 0, %41 ], [ -1, %39 ]
ret i32 %45
}