#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*/ X509;
typedef int /*<<< orphan*/ FILE;
typedef int /*<<< orphan*/ ASN1_TIME;

/* Variables and functions */
int /*<<< orphan*/ *PEM_read_X509(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *X509_get_notAfter(int /*<<< orphan*/ *);
int /*<<< orphan*/ convertAsn1ToString(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ convertAsn1ToTimestamp(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char *args[]) {
  if (argc == 1) {
    printf("Usage: %s [OPTIONS] [FILE]\n\n", args[0]);
    printf("Options:\n\t-u\t Print UNIX timestamp\n\n");
    return 1;
  }
  FILE *pemFile = fopen(args[argc - 1], "r");
  if (!pemFile) {
    fprintf(stderr, "Could not open file \"%s\"\n", args[argc - 1]);
    return 1;
  }
  X509 *cert = PEM_read_X509(pemFile, NULL, NULL, NULL);
  if (!cert) {
    fprintf(stderr, "Could not read PEM format\n");
    return 1;
  }
  char notAfterStr[128];
  ASN1_TIME *notAfter = X509_get_notAfter(cert);
  if (strcmp(args[1], "-u") == 0) {
    convertAsn1ToTimestamp(notAfter, notAfterStr);
  } else {
    convertAsn1ToString(notAfter, notAfterStr);
  }
  printf("%s\n", notAfterStr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe58(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1232 <main+0xb2>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <PEM_read_X509@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1277 <main+0xf7>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x20(%rbp),%rdi
call   1040 <X509_get_notAfter@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde3(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12bd <main+0x13d>
mov    -0xa8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   1080 <convertAsn1ToTimestamp@plt>
jmp    12d0 <main+0x150>
mov    -0xa8(%rbp),%rdi
lea    -0xa0(%rbp),%rsi
call   10a0 <convertAsn1ToString@plt>
lea    -0xa0(%rbp),%rsi
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jne    11cb <main+0x3b>
mov    (%r15),%rsi
lea    0xe52(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe9b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
jmp    1277 <main+0xe7>
movslq %edi,%rbx
mov    -0x8(%r15,%rbx,8),%rdi
lea    0xe43(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1224 <main+0x94>
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <PEM_read_X509@plt>
test   %rax,%rax
je     124a <main+0xba>
mov    %rax,%rdi
call   1050 <X509_get_notAfter@plt>
mov    %rax,%r14
mov    0x8(%r15),%rdi
lea    0xe47(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
test   %rax,%rax
je     1268 <main+0xd8>
call   10b0 <convertAsn1ToString@plt>
jmp    126d <main+0xdd>
add    $0xffffffffffffffff,%rbx
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
mov    (%r15,%rbx,8),%rdx
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    1277 <main+0xe7>
mov    0x2d8f(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%eax
jmp    1277 <main+0xe7>
call   1090 <convertAsn1ToTimestamp@plt>
mov    %rsp,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s [OPTIONS] [FILE]\0A\0A\00"
@.str.1 = [37 x i8] c"Options:\0A\09-u\09 Print UNIX timestamp\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"Could not open file \22%s\22\0A\00"
@.str.4 = [27 x i8] c"Could not read PEM format\0A\00"
@.str.5 = [3 x i8] c"-u\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [128 x 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 eq i32 %10, 1
br i1 %11, label %12, label %18
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 ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %64
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
%24 = load i8*, i8** %23
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = icmp ne i32* %26, null
br i1 %27, label %37, label %28
28: ; preds = %18
%29 = load i32, i32* @stderr
%30 = load i8**, i8*** %5
%31 = load i32, i32* %4
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %30, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %35)
store i32 1, i32* %3
br label %64
37: ; preds = %18
%38 = load i32*, i32** %6
%39 = call i32* @PEM_read_X509(i32* %38, i32* null, i32* null, i32* null)
store i32* %39, i32** %7
%40 = load i32*, i32** %7
%41 = icmp ne i32* %40, null
br i1 %41, label %45, label %42
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %64
45: ; preds = %37
%46 = load i32*, i32** %7
%47 = call i32* @X509_get_notAfter(i32* %46)
store i32* %47, i32** %9
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 1
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %45
%54 = load i32*, i32** %9
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%56 = call i32 @convertAsn1ToTimestamp(i32* %54, i8* %55)
br label %61
57: ; preds = %45
%58 = load i32*, i32** %9
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%60 = call i32 @convertAsn1ToString(i32* %58, i8* %59)
br label %61
61: ; preds = %57, %53
%62 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %61, %42, %28, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s [OPTIONS] [FILE]\0A\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [26 x i8] c"Could not open file \22%s\22\0A\00"
@.str.4 = [27 x i8] c"Could not read PEM format\0A\00"
@.str.5 = [3 x i8] c"-u\00"
@str = [36 x i8] c"Options:\0A\09-u\09 Print UNIX timestamp\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %39
9: ; preds = %2
%10 = add nsw i32 %0, -1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %1, i64 %11
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %12
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %18)
br label %39
20: ; preds = %9
%21 = tail call i32* @PEM_read_X509(i32* %14, i32* null, i32* null, i32* null)
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %39
26: ; preds = %20
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%28 = tail call i32* @X509_get_notAfter(i32* %21)
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @convertAsn1ToTimestamp(i32* %28, i8* %27)
br label %37
35: ; preds = %26
%36 = call i32 @convertAsn1ToString(i32* %28, i8* %27)
br label %37
37: ; preds = %35, %33
%38 = call i32 @puts(i8* %27)
br label %39
39: ; preds = %16, %37, %23, %5
%40 = phi i32 [ 1, %5 ], [ 1, %16 ], [ 0, %37 ], [ 1, %23 ]
ret i32 %40
}