#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 timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};
typedef int ssize_t;

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int /*<<< orphan*/,
                            int /*<<< orphan*/);
char *strchr(char *, char);
char *flu_ts_to_s(struct timespec *ts, char format) {
  char *r = calloc(10 + 1 + 9 + 1, sizeof(char));
  snprintf(r, 20, "%lis%09li", ts->tv_sec, ts->tv_nsec);
  ssize_t off = -1;
  if (format == 's')
    off = 0;
  else if (format == 'm')
    off = 3;
  else if (format == 'u')
    off = 6;
  if (off > -1)
    *(strchr(r, 's') + 1 + off) = '\0';
  return r;
}


x86 assembly (clang, -O0):
<flu_ts_to_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    $0x15,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    (%rax),%r8d
mov    $0x14,%esi
lea    0xe8d(%rip),%rdx
call   1040 <snprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x73,%eax
jne    1198 <flu_ts_to_s+0x68>
movl   $0x0,-0x1c(%rbp)
jmp    11cf <flu_ts_to_s+0x9f>
movsbl -0x9(%rbp),%eax
cmp    $0x6d,%eax
jne    11b1 <flu_ts_to_s+0x81>
movl   $0x3,-0x1c(%rbp)
jmp    11ca <flu_ts_to_s+0x9a>
movsbl -0x9(%rbp),%eax
cmp    $0x75,%eax
jne    11c5 <flu_ts_to_s+0x95>
movl   $0x6,-0x1c(%rbp)
jmp    11ca <flu_ts_to_s+0x9a>
jmp    11cf <flu_ts_to_s+0x9f>
cmpl   $0xffffffff,-0x1c(%rbp)
jle    11f0 <flu_ts_to_s+0xc0>
mov    -0x18(%rbp),%rdi
mov    $0x73,%esi
call   1030 <strchr@plt>
movslq -0x1c(%rbp),%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flu_ts_to_s>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x15,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
mov    (%rbx),%r8d
mov    0x4(%rbx),%ecx
lea    0xea8(%rip),%rdx
mov    %rax,%rdi
mov    $0x14,%esi
call   1040 <snprintf@plt>
cmp    $0x75,%bpl
je     117e <flu_ts_to_s+0x4e>
cmp    $0x73,%bpl
je     1185 <flu_ts_to_s+0x55>
cmp    $0x6d,%bpl
jne    1199 <flu_ts_to_s+0x69>
mov    $0x3,%ebx
jmp    1187 <flu_ts_to_s+0x57>
mov    $0x6,%ebx
jmp    1187 <flu_ts_to_s+0x57>
xor    %ebx,%ebx
mov    %r14,%rdi
mov    $0x73,%esi
call   1030 <strchr@plt>
movb   $0x0,0x1(%rax,%rbx,1)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [10 x i8] c"%lis%09li\00"
define i8* @flu_ts_to_s(%struct.timespec* %0, i8 signext %1) {
%3 = alloca %struct.timespec*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i32
store %struct.timespec* %0, %struct.timespec** %3
store i8 %1, i8* %4
%7 = call i8* @calloc(i32 21, i32 1)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load %struct.timespec*, %struct.timespec** %3
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14)
store i32 -1, i32* %6
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 115
br i1 %18, label %19, label %20
19: ; preds = %2
store i32 0, i32* %6
br label %32
20: ; preds = %2
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 109
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 3, i32* %6
br label %31
25: ; preds = %20
%26 = load i8, i8* %4
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 117
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 6, i32* %6
br label %30
30: ; preds = %29, %25
br label %31
31: ; preds = %30, %24
br label %32
32: ; preds = %31, %19
%33 = load i32, i32* %6
%34 = icmp sgt i32 %33, -1
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = call i8* @strchr(i8* %36, i8 signext 115)
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %35, %32
%43 = load i8*, i8** %5
ret i8* %43
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [10 x i8] c"%lis%09li\00"
define i8* @flu_ts_to_s(%struct.timespec* nocapture %0, i8 signext %1) {
%3 = tail call dereferenceable_or_null(21) i8* @calloc(i32 21, i32 1)
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @snprintf(i8* %3, i32 20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %7)
switch i8 %1, label %16 [
i8 115, label %11
i8 109, label %9
i8 117, label %10
]
9: ; preds = %2
br label %11
10: ; preds = %2
br label %11
11: ; preds = %9, %10, %2
%12 = phi i64 [ 0, %2 ], [ 6, %10 ], [ 3, %9 ]
%13 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 115)
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = getelementptr inbounds i8, i8* %14, i64 %12
store i8 0, i8* %15
br label %16
16: ; preds = %2, %11
ret i8* %3
}