#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 */
struct tm {
  int tm_wday;
};

/* Variables and functions */
char *out_str(char *, char *, char *);
char *abbreviated_weekday_name(char *buf, char *end, const struct tm *t) {
  if (t->tm_wday < 0 || t->tm_wday > 6)
    return NULL;
  static char *names[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  return out_str(buf, end, names[t->tm_wday]);
}


x86 assembly (clang, -O0):
<abbreviated_weekday_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jl     113e <abbreviated_weekday_name+0x2e>
mov    -0x20(%rbp),%rax
cmpl   $0x6,(%rax)
jle    114b <abbreviated_weekday_name+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    116e <abbreviated_weekday_name+0x5e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rax
movslq (%rax),%rcx
lea    0x2ecf(%rip),%rax
mov    (%rax,%rcx,8),%rdx
call   1030 <out_str@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<abbreviated_weekday_name>:
mov    (%rdx),%eax
cmp    $0x6,%rax
jbe    111b <abbreviated_weekday_name+0xb>
xor    %eax,%eax
ret
lea    0xede(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
add    %rcx,%rdx
jmp    1030 <out_str@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@abbreviated_weekday_name.names = internal global [7 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0)]
@.str = [4 x i8] c"Sun\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@.str.6 = [4 x i8] c"Sat\00"
define i8* @abbreviated_weekday_name(i8* %0, i8* %1, %struct.tm* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.tm*
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.tm* %2, %struct.tm** %7
%8 = load %struct.tm*, %struct.tm** %7
%9 = getelementptr inbounds %struct.tm, %struct.tm* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = icmp slt i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %3
%13 = load %struct.tm*, %struct.tm** %7
%14 = getelementptr inbounds %struct.tm, %struct.tm* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = icmp sgt i32 %15, 6
br i1 %16, label %17, label %18
17: ; preds = %12, %3
store i8* null, i8** %4
br label %28
18: ; preds = %12
%19 = load i8*, i8** %5
%20 = load i8*, i8** %6
%21 = load %struct.tm*, %struct.tm** %7
%22 = getelementptr inbounds %struct.tm, %struct.tm* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [7 x i8*], [7 x i8*]* @abbreviated_weekday_name.names, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @out_str(i8* %19, i8* %20, i8* %26)
store i8* %27, i8** %4
br label %28
28: ; preds = %18, %17
%29 = load i8*, i8** %4
ret i8* %29
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@reltable.abbreviated_weekday_name = internal unnamed_addr constant [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.abbreviated_weekday_name to i64)) to i32)]
@.str = [4 x i8] c"Sun\00"
@.str.1 = [4 x i8] c"Mon\00"
@.str.2 = [4 x i8] c"Tue\00"
@.str.3 = [4 x i8] c"Wed\00"
@.str.4 = [4 x i8] c"Thu\00"
@.str.5 = [4 x i8] c"Fri\00"
@.str.6 = [4 x i8] c"Sat\00"
define i8* @abbreviated_weekday_name(i8* %0, i8* %1, %struct.tm* nocapture %2) {
%4 = getelementptr inbounds %struct.tm, %struct.tm* %2, i64 0, i32 0
%5 = load i32, i32* %4
%6 = icmp ugt i32 %5, 6
br i1 %6, label %12, label %7
7: ; preds = %3
%8 = zext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.abbreviated_weekday_name to i8*), i64 %9)
%11 = tail call i8* @out_str(i8* %0, i8* %1, i8* %10)
br label %12
12: ; preds = %3, %7
%13 = phi i8* [ %11, %7 ], [ null, %3 ]
ret i8* %13
}