#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 */

/* Variables and functions */
scalar_t__ atoi(char const *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int strspn(char const *, char *);
char *format_time(char *buffer, const char *string) {
  if (strcmp(string, "forever") == 0 || strcmp(string, "-") == 0 ||
      atoi(string) < 0)
    strcpy(buffer, "forever");
  else if (strcmp(string, "none") == 0 || strcmp(string, "0") == 0)
    strcpy(buffer, "none");
  else {
    char worktime[80 + 1];
    const char *suffix;
    char *format;
    int int_time;
    suffix = string + strspn(string, "0123456789");
    strncpy(worktime, string, suffix - string);
    worktime[suffix - string] = '\0';
    int_time = atoi(worktime);
    switch (*suffix) {
    case 'm':
      format = "%d minute(s)";
      break;
    case 'h':
      format = "%d hour(s)";
      break;
    case 'd':
      format = "%d day(s)";
      break;
    case 's':
    case '\0':
    default:
      format = "%d second(s)";
      break;
    }
    sprintf(buffer, format, int_time);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<format_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ba <format_time+0x5a>
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11ba <format_time+0x5a>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x0,%rax
jge    11cf <format_time+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1040 <strcpy@plt>
jmp    1341 <format_time+0x1e1>
mov    -0x10(%rbp),%rdi
lea    0xe30(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1203 <format_time+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1218 <format_time+0xb8>
mov    -0x8(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   1040 <strcpy@plt>
jmp    133c <format_time+0x1dc>
mov    -0x10(%rbp),%rdi
mov    %rdi,-0x98(%rbp)
lea    0xde7(%rip),%rsi
call   1050 <strspn@plt>
mov    %eax,%ecx
mov    -0x98(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x78(%rbp),%edx
mov    %esi,%eax
sub    %eax,%edx
lea    -0x70(%rbp),%rdi
mov    %rdi,-0x90(%rbp)
call   1030 <strncpy@plt>
mov    -0x90(%rbp),%rdi
mov    -0x78(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x70(%rbp,%rax,1)
call   1070 <atoi@plt>
mov    %eax,-0x84(%rbp)
mov    -0x78(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x88(%rbp)
test   %eax,%eax
je     1319 <format_time+0x1b9>
jmp    1299 <format_time+0x139>
mov    -0x88(%rbp),%eax
sub    $0x64,%eax
je     1309 <format_time+0x1a9>
jmp    12ad <format_time+0x14d>
mov    -0x88(%rbp),%eax
sub    $0x68,%eax
je     12f9 <format_time+0x199>
jmp    12c1 <format_time+0x161>
mov    -0x88(%rbp),%eax
sub    $0x6d,%eax
je     12e9 <format_time+0x189>
jmp    12d5 <format_time+0x175>
mov    -0x88(%rbp),%eax
sub    $0x73,%eax
je     1319 <format_time+0x1b9>
jmp    131e <format_time+0x1be>
lea    0xd2c(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    1329 <format_time+0x1c9>
lea    0xd29(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    1329 <format_time+0x1c9>
lea    0xd24(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    1329 <format_time+0x1c9>
jmp    131e <format_time+0x1be>
lea    0xd19(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
call   1080 <sprintf@plt>
jmp    1341 <format_time+0x1e1>
mov    -0x8(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_time>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1223 <format_time+0xc3>
lea    0xe78(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1223 <format_time+0xc3>
mov    %rbx,%rdi
call   1070 <atoi@plt>
test   %rax,%rax
js     1223 <format_time+0xc3>
lea    0xe55(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1241 <format_time+0xe1>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1241 <format_time+0xe1>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strspn@plt>
movslq %eax,%r15
mov    %rsp,%r12
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%r15,1)
mov    %r12,%rdi
call   1070 <atoi@plt>
movsbl (%rbx,%r15,1),%ecx
cmp    $0x64,%ecx
je     124a <format_time+0xea>
cmp    $0x6d,%ecx
je     1253 <format_time+0xf3>
cmp    $0x68,%ecx
jne    125c <format_time+0xfc>
lea    0xe08(%rip),%rsi
jmp    1263 <format_time+0x103>
lea    0xdd6(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdc2(%rip),%rsi
jmp    122a <format_time+0xca>
lea    0xde3(%rip),%rsi
jmp    1263 <format_time+0x103>
lea    0xdc2(%rip),%rsi
jmp    1263 <format_time+0x103>
lea    0xddb(%rip),%rsi
mov    %r14,%rdi
mov    %eax,%edx
call   1080 <sprintf@plt>
jmp    1232 <format_time+0xd2>

LLVM IR (-O0):
@.str = [8 x i8] c"forever\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [11 x i8] c"0123456789\00"
@.str.5 = [13 x i8] c"%d minute(s)\00"
@.str.6 = [11 x i8] c"%d hour(s)\00"
@.str.7 = [10 x i8] c"%d day(s)\00"
@.str.8 = [13 x i8] c"%d second(s)\00"
define i8* @format_time(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [81 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %4
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i64 @atoi(i8* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16, %12, %2
%21 = load i8*, i8** %3
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %72
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i8*, i8** %4
%29 = call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %27, %23
%32 = load i8*, i8** %3
%33 = call i32 @strcpy(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %71
34: ; preds = %27
%35 = load i8*, i8** %4
%36 = load i8*, i8** %4
%37 = call i32 @strspn(i8* %36, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8* %39, i8** %6
%40 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%41 = load i8*, i8** %4
%42 = load i8*, i8** %6
%43 = load i8*, i8** %4
%44 = ptrtoint i8* %42 to i64
%45 = ptrtoint i8* %43 to i64
%46 = sub i64 %44, %45
%47 = trunc i64 %46 to i32
%48 = call i32 @strncpy(i8* %40, i8* %41, i32 %47)
%49 = load i8*, i8** %6
%50 = load i8*, i8** %4
%51 = ptrtoint i8* %49 to i64
%52 = ptrtoint i8* %50 to i64
%53 = sub i64 %51, %52
%54 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 %53
store i8 0, i8* %54
%55 = getelementptr inbounds [81 x i8], [81 x i8]* %5, i64 0, i64 0
%56 = call i64 @atoi(i8* %55)
%57 = trunc i64 %56 to i32
store i32 %57, i32* %8
%58 = load i8*, i8** %6
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
switch i32 %60, label %65 [
i32 109, label %61
i32 104, label %62
i32 100, label %63
i32 115, label %64
i32 0, label %64
]
61: ; preds = %34
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8** %7
br label %66
62: ; preds = %34
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8** %7
br label %66
63: ; preds = %34
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8** %7
br label %66
64: ; preds = %34, %34
br label %65
65: ; preds = %34, %64
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i8** %7
br label %66
66: ; preds = %65, %63, %62, %61
%67 = load i8*, i8** %3
%68 = load i8*, i8** %7
%69 = load i32, i32* %8
%70 = call i32 @sprintf(i8* %67, i8* %68, i32 %69)
br label %71
71: ; preds = %66, %31
br label %72
72: ; preds = %71, %20
%73 = load i8*, i8** %3
ret i8* %73
}

LLVM IR (-O2):
@.str = [8 x i8] c"forever\00"
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [5 x i8] c"none\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [11 x i8] c"0123456789\00"
@.str.5 = [13 x i8] c"%d minute(s)\00"
@.str.6 = [11 x i8] c"%d hour(s)\00"
@.str.7 = [10 x i8] c"%d day(s)\00"
@.str.8 = [13 x i8] c"%d second(s)\00"
define i8* @format_time(i8* returned %0, i8* %1) {
%3 = alloca [81 x i8]
%4 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i64 @atoi(i8* %1)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9, %6, %2
%13 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %39
14: ; preds = %9
%15 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17, %14
%21 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %39
22: ; preds = %17
%23 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 0
%24 = tail call i32 @strspn(i8* %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = call i32 @strncpy(i8* %23, i8* %1, i32 %24)
%28 = getelementptr inbounds [81 x i8], [81 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %28
%29 = call i64 @atoi(i8* %23)
%30 = trunc i64 %29 to i32
%31 = load i8, i8* %26
%32 = sext i8 %31 to i32
switch i32 %32, label %35 [
i32 109, label %36
i32 104, label %33
i32 100, label %34
]
33: ; preds = %22
br label %36
34: ; preds = %22
br label %36
35: ; preds = %22
br label %36
36: ; preds = %22, %35, %34, %33
%37 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), %35 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), %34 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), %33 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), %22 ]
%38 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %37, i32 %30)
br label %39
39: ; preds = %20, %36, %12
ret i8* %0
}