int report_validity(char *buffer, int validity_period) {
  int result = 0;
  int n;
  char *p;
  if (validity_period < 0 || validity_period > 255)
    sprintf(buffer, "invalid (%i)", validity_period);
  else {
    if (validity_period <= 143) {
      n = (validity_period + 1) * 5;
      p = "min";
    } else if (validity_period <= 167) {
      n = 12 + (validity_period - 143) / 2;
      p = "hour";
    } else if (validity_period <= 196) {
      n = validity_period - 166;
      p = "day";
    } else {
      n = validity_period - 192;
      p = "week";
    }
    sprintf(buffer, "%i %s%s (%i)", n, p, (n > 1) ? "s" : "", validity_period);
    result = 1;
  }
  return result;
}


x86 assembly (clang, -O0):
<report_validity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     113d <report_validity+0x2d>
cmpl   $0xff,-0xc(%rbp)
jle    1157 <report_validity+0x47>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xeb5(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    1237 <report_validity+0x127>
cmpl   $0x8f,-0xc(%rbp)
jg     1180 <report_validity+0x70>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
imul   $0x5,%eax,%eax
mov    %eax,-0x14(%rbp)
lea    0xe96(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11fb <report_validity+0xeb>
cmpl   $0xa7,-0xc(%rbp)
jg     11b3 <report_validity+0xa3>
mov    -0xc(%rbp),%eax
sub    $0x8f,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0xc,%eax
mov    %eax,-0x14(%rbp)
lea    0xe67(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f6 <report_validity+0xe6>
cmpl   $0xc4,-0xc(%rbp)
jg     11db <report_validity+0xcb>
mov    -0xc(%rbp),%eax
sub    $0xa6,%eax
mov    %eax,-0x14(%rbp)
lea    0xe44(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f1 <report_validity+0xe1>
mov    -0xc(%rbp),%eax
sub    $0xc0,%eax
mov    %eax,-0x14(%rbp)
lea    0xe2d(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11f6 <report_validity+0xe6>
jmp    11fb <report_validity+0xeb>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    -0x14(%rbp),%esi
lea    0xdfc(%rip),%r8
lea    0xe15(%rip),%rax
cmp    $0x1,%esi
cmovg  %rax,%r8
mov    -0xc(%rbp),%r9d
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_validity>:
push   %rbx
mov    %esi,%r9d
cmp    $0x100,%esi
jb     1131 <report_validity+0x21>
lea    0xedd(%rip),%rsi
xor    %ebx,%ebx
mov    %r9d,%edx
xor    %eax,%eax
call   1030 <sprintf@plt>
jmp    11a9 <report_validity+0x99>
cmp    $0x8f,%r9d
ja     114a <report_validity+0x3a>
lea    (%r9,%r9,4),%edx
add    $0x5,%edx
lea    0xec5(%rip),%rcx
jmp    118f <report_validity+0x7f>
cmp    $0xa7,%r9d
ja     1168 <report_validity+0x58>
lea    0x71(%r9),%edx
shr    %edx
and    $0x7f,%edx
add    $0xc,%edx
lea    0xeab(%rip),%rcx
jmp    118f <report_validity+0x7f>
cmp    $0xc4,%r9d
ja     1181 <report_validity+0x71>
lea    -0xa6(%r9),%edx
lea    0xe97(%rip),%rcx
jmp    118f <report_validity+0x7f>
lea    -0xc0(%r9),%edx
lea    0xe8b(%rip),%rcx
lea    0xe89(%rip),%rsi
lea    0xe8f(%rip),%r8
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [13 x i8] c"invalid (%i)\00"
@.str.1 = [4 x i8] c"min\00"
@.str.2 = [5 x i8] c"hour\00"
@.str.3 = [4 x i8] c"day\00"
@.str.4 = [5 x i8] c"week\00"
@.str.5 = [13 x i8] c"%i %s%s (%i)\00"
@.str.6 = [2 x i8] c"s\00"
@.str.7 = [1 x i8] zeroinitializer
define i32 @report_validity(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 255
br i1 %12, label %13, label %17
13: ; preds = %10, %2
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %53
17: ; preds = %10
%18 = load i32, i32* %4
%19 = icmp sle i32 %18, 143
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
%23 = mul nsw i32 %22, 5
store i32 %23, i32* %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %43
24: ; preds = %17
%25 = load i32, i32* %4
%26 = icmp sle i32 %25, 167
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 143
%30 = sdiv i32 %29, 2
%31 = add nsw i32 12, %30
store i32 %31, i32* %6
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %7
br label %42
32: ; preds = %24
%33 = load i32, i32* %4
%34 = icmp sle i32 %33, 196
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %4
%37 = sub nsw i32 %36, 166
store i32 %37, i32* %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %7
br label %41
38: ; preds = %32
%39 = load i32, i32* %4
%40 = sub nsw i32 %39, 192
store i32 %40, i32* %6
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %7
br label %41
41: ; preds = %38, %35
br label %42
42: ; preds = %41, %27
br label %43
43: ; preds = %42, %20
%44 = load i8*, i8** %3
%45 = load i32, i32* %6
%46 = load i8*, i8** %7
%47 = load i32, i32* %6
%48 = icmp sgt i32 %47, 1
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0)
%51 = load i32, i32* %4
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %44, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %45, i8* %46, i8* %50, i32 %51)
store i32 1, i32* %5
br label %53
53: ; preds = %43, %13
%54 = load i32, i32* %5
ret i32 %54
}

LLVM IR (-O2):
@.str = [13 x i8] c"invalid (%i)\00"
@.str.1 = [4 x i8] c"min\00"
@.str.2 = [5 x i8] c"hour\00"
@.str.3 = [4 x i8] c"day\00"
@.str.4 = [5 x i8] c"week\00"
@.str.5 = [13 x i8] c"%i %s%s (%i)\00"
@.str.6 = [2 x i8] c"s\00"
define i32 @report_validity(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp ugt i32 %1, 255
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %28
6: ; preds = %2
%7 = icmp ult i32 %1, 144
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = mul nuw nsw i32 %1, 5
%10 = add nuw nsw i32 %9, 5
br label %24
11: ; preds = %6
%12 = icmp ult i32 %1, 168
br i1 %12, label %13, label %18
13: ; preds = %11
%14 = add nuw nsw i32 %1, 113
%15 = lshr i32 %14, 1
%16 = and i32 %15, 127
%17 = add nuw nsw i32 %16, 12
br label %24
18: ; preds = %11
%19 = icmp ult i32 %1, 197
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = add nsw i32 %1, -166
br label %24
22: ; preds = %18
%23 = add nsw i32 %1, -192
br label %24
24: ; preds = %13, %22, %20, %8
%25 = phi i32 [ %10, %8 ], [ %17, %13 ], [ %21, %20 ], [ %23, %22 ]
%26 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %13 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %20 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %22 ]
%27 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 %25, i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 %1)
br label %28
28: ; preds = %24, %4
%29 = phi i32 [ 0, %4 ], [ 1, %24 ]
ret i32 %29
}