#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*/ value;
typedef scalar_t__ time_t;
typedef int /*<<< orphan*/ retention;
typedef unsigned short int64_t;

/* Variables and functions */
char *ctime(scalar_t__ *);
int /*<<< orphan*/ errno;
int lgetxattr(char *, char *, unsigned short *, int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int /*<<< orphan*/);
scalar_t__ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  unsigned short retention;
  int status;
  time_t expiration;
  char *path;
  time_t now;
  int64_t value;
  char *timeString;
  if (argc < 2) {
    printf("Bad arguments, expected syntax: getretention <path>\n");
    return 0;
  }
  path = argv[1];
  status = lgetxattr(path, "user.Retention", &retention, sizeof(retention));
  if (status < 0) {
    printf("Cannot get retention: %s\n", strerror(errno));
  } else {
    printf("Retention is %hu day(s)\n", retention);
  }
  status = lgetxattr(path, "user.ExpirationDate", &value, sizeof(value));
  if (status < 0) {
    printf("Cannot get expiration date: %s\n", strerror(errno));
  } else {
    expiration = value;
    timeString = ctime(&expiration);
    if (timeString == NULL)
      printf("Expiration date is (NULL)\n");
    else
      printf("Expiration date is %s\n", timeString);
    now = time(NULL);
    if (now > expiration) {
      printf("Media is expired\n");
    } else {
      printf("Media is not expired\n");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x3a>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <main+0x179>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe94(%rip),%rsi
lea    -0x12(%rbp),%rdx
mov    $0x2,%ecx
call   1030 <lgetxattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11e0 <main+0x90>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11f2 <main+0xa2>
movzwl -0x12(%rbp),%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x32(%rbp),%rdx
mov    $0x2,%ecx
call   1030 <lgetxattr@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    123c <main+0xec>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %rax,%rsi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c2 <main+0x172>
movzwl -0x32(%rbp),%eax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <ctime@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    126f <main+0x11f>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1281 <main+0x131>
mov    -0x40(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jle    12af <main+0x15f>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12bd <main+0x16d>
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c2 <main+0x172>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jg     1176 <main+0x16>
lea    0xf5c(%rip),%rdi
jmp    125f <main+0xff>
mov    0x8(%rsi),%rbx
lea    0xe7f(%rip),%rsi
lea    0x6(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x2,%ecx
call   1040 <lgetxattr@plt>
test   %eax,%eax
js     11ac <main+0x4c>
movzwl 0x6(%rsp),%esi
lea    0xe86(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11cb <main+0x6b>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe4e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe70(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
mov    $0x2,%ecx
call   1040 <lgetxattr@plt>
test   %eax,%eax
js     1214 <main+0xb4>
movzwl 0x4(%rsp),%eax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <ctime@plt>
test   %rax,%rax
je     1235 <main+0xd5>
lea    0xe6e(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1241 <main+0xe1>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe2d(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1264 <main+0x104>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <time@plt>
cmp    0x8(%rsp),%rax
jle    1258 <main+0xf8>
lea    0xe4c(%rip),%rdi
jmp    125f <main+0xff>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Bad arguments, expected syntax: getretention <path>\0A\00"
@.str.1 = [15 x i8] c"user.Retention\00"
@.str.2 = [26 x i8] c"Cannot get retention: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"Retention is %hu day(s)\0A\00"
@.str.4 = [20 x i8] c"user.ExpirationDate\00"
@.str.5 = [32 x i8] c"Cannot get expiration date: %s\0A\00"
@.str.6 = [27 x i8] c"Expiration date is (NULL)\0A\00"
@.str.7 = [23 x i8] c"Expiration date is %s\0A\00"
@.str.8 = [18 x i8] c"Media is expired\0A\00"
@.str.9 = [22 x i8] c"Media is not expired\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i16
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 2
br i1 %14, label %15, label %17
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %9
%21 = load i8*, i8** %9
%22 = call i32 @lgetxattr(i8* %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i16* %6, i32 2)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %33
29: ; preds = %17
%30 = load i16, i16* %6
%31 = zext i16 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %29, %25
%34 = load i8*, i8** %9
%35 = call i32 @lgetxattr(i8* %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i16* %11, i32 2)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %40)
br label %63
42: ; preds = %33
%43 = load i16, i16* %11
%44 = zext i16 %43 to i64
store i64 %44, i64* %8
%45 = call i8* @ctime(i64* %8)
store i8* %45, i8** %12
%46 = load i8*, i8** %12
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %53
50: ; preds = %42
%51 = load i8*, i8** %12
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %50, %48
%54 = call i64 @time(i32* null)
store i64 %54, i64* %10
%55 = load i64, i64* %10
%56 = load i64, i64* %8
%57 = icmp sgt i64 %55, %56
br i1 %57, label %58, label %60
58: ; preds = %53
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0))
br label %62
60: ; preds = %53
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
br label %62
62: ; preds = %60, %58
br label %63
63: ; preds = %62, %38
store i32 0, i32* %3
br label %64
64: ; preds = %63, %15
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"user.Retention\00"
@.str.2 = [26 x i8] c"Cannot get retention: %s\0A\00"
@errno = global i32 0
@.str.3 = [25 x i8] c"Retention is %hu day(s)\0A\00"
@.str.4 = [20 x i8] c"user.ExpirationDate\00"
@.str.5 = [32 x i8] c"Cannot get expiration date: %s\0A\00"
@.str.7 = [23 x i8] c"Expiration date is %s\0A\00"
@str = [21 x i8] c"Media is not expired\00"
@str.10 = [17 x i8] c"Media is expired\00"
@str.11 = [26 x i8] c"Expiration date is (NULL)\00"
@str.12 = [52 x i8] c"Bad arguments, expected syntax: getretention <path>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i64
%5 = alloca i16
%6 = bitcast i16* %3 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i16* %5 to i8*
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.12, i64 0, i64 0))
br label %49
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i32 @lgetxattr(i8* %14, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i16* %3, i32 2)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %25
21: ; preds = %12
%22 = load i16, i16* %3
%23 = zext i16 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %17
%26 = call i32 @lgetxattr(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i16* %5, i32 2)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %30)
br label %49
32: ; preds = %25
%33 = load i16, i16* %5
%34 = zext i16 %33 to i64
store i64 %34, i64* %4
%35 = call i8* @ctime(i64* %4)
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
br label %41
39: ; preds = %32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %35)
br label %41
41: ; preds = %39, %37
%42 = call i64 @time(i32* null)
%43 = load i64, i64* %4
%44 = icmp sgt i64 %42, %43
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.10, i64 0, i64 0))
br label %49
47: ; preds = %41
%48 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %49
49: ; preds = %28, %47, %45, %10
ret i32 0
}