#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 {
  int dummy;
};

/* Variables and functions */
struct tm *gmtime(int *);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ strftime(char *, int, char *, struct tm *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int time(int /*<<< orphan*/ *);
int reltimestr(time_t tweettime, char *outstr) {
  char res[8];
  memset(&res, 0, 8);
  int value = 0;
  char *append = NULL;
  int norel = 0, noval = 0;
  time_t curtime = time(NULL);
  time_t timediff = curtime - tweettime;
  struct tm *noreltime = gmtime(&tweettime);
  if (timediff < 60) {
    value = timediff;
    noval = 1;
    append = "<1m";
  } else if (timediff < 3600) {
    value = timediff / 60;
    append = "m";
  } else if (timediff < 3600 * 24) {
    value = timediff / 3600;
    append = "h";
  } else
    norel = 1;
  if (norel) {
    strftime(res, 8, "%d %b", noreltime);
  } else {
    if (noval)
      snprintf(res, 8, "%s", append);
    else
      snprintf(res, 8, "%d%s", value, append);
  }
  strncpy(outstr, res, 8);
  return 0;
}


x86 assembly (clang, -O0):
<reltimestr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
sub    -0x4(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x4(%rbp),%rdi
call   1080 <gmtime@plt>
mov    %rax,-0x40(%rbp)
cmpl   $0x3c,-0x38(%rbp)
jge    11e5 <reltimestr+0x85>
mov    -0x38(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x30(%rbp)
lea    0xe24(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    124c <reltimestr+0xec>
cmpl   $0xe10,-0x38(%rbp)
jge    1210 <reltimestr+0xb0>
mov    -0x38(%rbp),%eax
mov    $0x3c,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
lea    0xdfb(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1247 <reltimestr+0xe7>
cmpl   $0x15180,-0x38(%rbp)
jge    123b <reltimestr+0xdb>
mov    -0x38(%rbp),%eax
mov    $0xe10,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
lea    0xdd2(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1242 <reltimestr+0xe2>
movl   $0x1,-0x2c(%rbp)
jmp    1247 <reltimestr+0xe7>
jmp    124c <reltimestr+0xec>
cmpl   $0x0,-0x2c(%rbp)
je     1274 <reltimestr+0x114>
lea    -0x18(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    $0x8,%esi
lea    0xd9c(%rip),%rdx
call   1070 <strftime@plt>
jmp    12c1 <reltimestr+0x161>
cmpl   $0x0,-0x30(%rbp)
je     129e <reltimestr+0x13e>
lea    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x8,%esi
lea    0xd7c(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12bc <reltimestr+0x15c>
lea    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    $0x8,%esi
lea    0xd57(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    12c1 <reltimestr+0x161>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reltimestr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
mov    %edi,0xc(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%ebp
sub    %ebx,%ebp
lea    0xc(%rsp),%rdi
call   1080 <gmtime@plt>
cmp    $0x3c,%ebp
jge    11b9 <reltimestr+0x59>
lea    0xe6d(%rip),%rdx
lea    0xe58(%rip),%rcx
mov    %rsp,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    1223 <reltimestr+0xc3>
cmp    $0xe0f,%ebp
ja     11d6 <reltimestr+0x76>
movzwl %bp,%eax
imul   $0x8889,%eax,%ecx
shr    $0x15,%ecx
lea    0xe2e(%rip),%r8
jmp    11f4 <reltimestr+0x94>
cmp    $0x1517f,%ebp
ja     120c <reltimestr+0xac>
mov    %ebp,%eax
mov    $0x91a2b3c5,%ecx
imul   %rax,%rcx
shr    $0x2b,%rcx
lea    0xe10(%rip),%r8
lea    0xe11(%rip),%rdx
mov    %rsp,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
jmp    1223 <reltimestr+0xc3>
lea    0xdf3(%rip),%rdx
mov    %rsp,%rdi
mov    $0x8,%esi
mov    %rax,%rcx
call   1070 <strftime@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0x8,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [4 x i8] c"<1m\00"
@.str.1 = [2 x i8] c"m\00"
@.str.2 = [2 x i8] c"h\00"
@.str.3 = [6 x i8] c"%d %b\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%d%s\00"
define i32 @reltimestr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [8 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.tm*
store i32 %0, i32* %3
store i8* %1, i8** %4
%13 = bitcast [8 x i8]* %5 to i8**
%14 = call i32 @memset(i8** %13, i32 0, i32 8)
store i32 0, i32* %6
store i8* null, i8** %7
store i32 0, i32* %8
store i32 0, i32* %9
%15 = call i32 @time(i32* null)
store i32 %15, i32* %10
%16 = load i32, i32* %10
%17 = load i32, i32* %3
%18 = sub nsw i32 %16, %17
store i32 %18, i32* %11
%19 = call %struct.tm* @gmtime(i32* %3)
store %struct.tm* %19, %struct.tm** %12
%20 = load i32, i32* %11
%21 = icmp slt i32 %20, 60
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = load i32, i32* %11
store i32 %23, i32* %6
store i32 1, i32* %9
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
br label %39
24: ; preds = %2
%25 = load i32, i32* %11
%26 = icmp slt i32 %25, 3600
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %11
%29 = sdiv i32 %28, 60
store i32 %29, i32* %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %38
30: ; preds = %24
%31 = load i32, i32* %11
%32 = icmp slt i32 %31, 86400
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %11
%35 = sdiv i32 %34, 3600
store i32 %35, i32* %6
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %37
36: ; preds = %30
store i32 1, i32* %8
br label %37
37: ; preds = %36, %33
br label %38
38: ; preds = %37, %27
br label %39
39: ; preds = %38, %22
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%44 = load %struct.tm*, %struct.tm** %12
%45 = call i32 @strftime(i8* %43, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %44)
br label %59
46: ; preds = %39
%47 = load i32, i32* %9
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%51 = load i8*, i8** %7
%52 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %50, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %58
53: ; preds = %46
%54 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%55 = load i32, i32* %6
%56 = load i8*, i8** %7
%57 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %54, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %55, i8* %56)
br label %58
58: ; preds = %53, %49
br label %59
59: ; preds = %58, %42
%60 = load i8*, i8** %4
%61 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%62 = call i32 @strncpy(i8* %60, i8* %61, i32 8)
ret i32 0
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [4 x i8] c"<1m\00"
@.str.1 = [2 x i8] c"m\00"
@.str.2 = [2 x i8] c"h\00"
@.str.3 = [6 x i8] c"%d %b\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%d%s\00"
define i32 @reltimestr(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = bitcast i8** %4 to i8*
%6 = call i32 @memset(i8** %4, i32 0, i32 8)
%7 = call i32 @time(i32* null)
%8 = sub nsw i32 %7, %0
%9 = call %struct.tm* @gmtime(i32* %3)
%10 = icmp slt i32 %8, 60
br i1 %10, label %23, label %11
11: ; preds = %2
%12 = icmp ult i32 %8, 3600
br i1 %12, label %13, label %17
13: ; preds = %11
%14 = trunc i32 %8 to i16
%15 = udiv i16 %14, 60
%16 = zext i16 %15 to i32
br label %25
17: ; preds = %11
%18 = icmp ult i32 %8, 86400
br i1 %18, label %19, label %21
19: ; preds = %17
%20 = udiv i32 %8, 3600
br label %25
21: ; preds = %17
%22 = call i32 @strftime(i8* %5, i32 8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.tm* %9)
br label %29
23: ; preds = %2
%24 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %19, %13
%26 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %13 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), %19 ]
%27 = phi i32 [ %16, %13 ], [ %20, %19 ]
%28 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %5, i32 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %27, i8* %26)
br label %29
29: ; preds = %23, %25, %21
%30 = call i32 @strncpy(i8* %1, i8* %5, i32 8)
ret i32 0
}