#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 */
int fs_sexa(char *, double, int, int);
int sprintf(char *, char const *, double);
int sscanf(char const *, char *, int *, int *, char *);
int numberFormat(char *buf, const char *format, double value) {
  int w, f, s;
  char m;
  if (sscanf(format, "%%%d.%d%c", &w, &f, &m) == 3 && m == 'm') {
    switch (f) {
    case 9:
      s = 360000;
      break;
    case 8:
      s = 36000;
      break;
    case 6:
      s = 3600;
      break;
    case 5:
      s = 600;
      break;
    default:
      s = 60;
      break;
    }
    return (fs_sexa(buf, value, w - f, s));
  } else {
    return (sprintf(buf, format, value));
  }
}


x86 assembly (clang, -O0):
<numberFormat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xec4(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
lea    -0x2d(%rbp),%r8
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    11f6 <numberFormat+0xc6>
movsbl -0x2d(%rbp),%eax
cmp    $0x6d,%eax
jne    11f6 <numberFormat+0xc6>
mov    -0x28(%rbp),%eax
add    $0xfffffffb,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x4,%eax
ja     11d0 <numberFormat+0xa0>
mov    -0x38(%rbp),%rax
lea    0xe69(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x57e40,-0x2c(%rbp)
jmp    11d7 <numberFormat+0xa7>
movl   $0x8ca0,-0x2c(%rbp)
jmp    11d7 <numberFormat+0xa7>
movl   $0xe10,-0x2c(%rbp)
jmp    11d7 <numberFormat+0xa7>
movl   $0x258,-0x2c(%rbp)
jmp    11d7 <numberFormat+0xa7>
movl   $0x3c,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    -0x24(%rbp),%esi
sub    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1030 <fs_sexa@plt>
mov    %eax,-0x4(%rbp)
jmp    120b <numberFormat+0xdb>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsd  -0x20(%rbp),%xmm0
call   1050 <sprintf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numberFormat>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xeb6(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
lea    0x7(%rsp),%r8
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x3,%eax
jne    11a1 <numberFormat+0x71>
cmpb   $0x6d,0x7(%rsp)
jne    11a1 <numberFormat+0x71>
mov    0x8(%rsp),%eax
lea    -0x5(%rax),%ecx
mov    $0x3c,%edx
cmp    $0x4,%ecx
ja     118b <numberFormat+0x5b>
movslq %ecx,%rcx
lea    0xe84(%rip),%rdx
mov    (%rdx,%rcx,4),%edx
mov    0xc(%rsp),%esi
sub    %eax,%esi
mov    %r14,%rdi
movsd  0x10(%rsp),%xmm0
call   1030 <fs_sexa@plt>
jmp    11b2 <numberFormat+0x82>
mov    %r14,%rdi
mov    %rbx,%rsi
movsd  0x10(%rsp),%xmm0
call   1050 <sprintf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%%%d.%d%c\00"
define i32 @numberFormat(i8* %0, i8* %1, double %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca double
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i8* %0, i8** %5
store i8* %1, i8** %6
store double %2, double* %7
%12 = load i8*, i8** %6
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %8, i32* %9, i8* %11)
%14 = icmp eq i32 %13, 3
br i1 %14, label %15, label %34
15: ; preds = %3
%16 = load i8, i8* %11
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 109
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i32, i32* %9
switch i32 %20, label %25 [
i32 9, label %21
i32 8, label %22
i32 6, label %23
i32 5, label %24
]
21: ; preds = %19
store i32 360000, i32* %10
br label %26
22: ; preds = %19
store i32 36000, i32* %10
br label %26
23: ; preds = %19
store i32 3600, i32* %10
br label %26
24: ; preds = %19
store i32 600, i32* %10
br label %26
25: ; preds = %19
store i32 60, i32* %10
br label %26
26: ; preds = %25, %24, %23, %22, %21
%27 = load i8*, i8** %5
%28 = load double, double* %7
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = sub nsw i32 %29, %30
%32 = load i32, i32* %10
%33 = call i32 @fs_sexa(i8* %27, double %28, i32 %31, i32 %32)
store i32 %33, i32* %4
br label %39
34: ; preds = %15, %3
%35 = load i8*, i8** %5
%36 = load i8*, i8** %6
%37 = load double, double* %7
%38 = call i32 @sprintf(i8* %35, i8* %36, double %37)
store i32 %38, i32* %4
br label %39
39: ; preds = %34, %26
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
@.str = [10 x i8] c"%%%d.%d%c\00"
@switch.table.numberFormat = [5 x i32] [i32 600, i32 3600, i32 60, i32 36000, i32 360000]
define i32 @numberFormat(i8* %0, i8* nocapture %1, double %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @sscanf(i8* %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %4, i32* %5, i8* %6)
%10 = icmp eq i32 %9, 3
%11 = load i8, i8* %6
%12 = icmp eq i8 %11, 109
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %27
14: ; preds = %3
%15 = load i32, i32* %5
%16 = add i32 %15, -5
%17 = icmp ult i32 %16, 5
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = sext i32 %16 to i64
%20 = getelementptr inbounds [5 x i32], [5 x i32]* @switch.table.numberFormat, i64 0, i64 %19
%21 = load i32, i32* %20
br label %22
22: ; preds = %14, %18
%23 = phi i32 [ %21, %18 ], [ 60, %14 ]
%24 = load i32, i32* %4
%25 = sub nsw i32 %24, %15
%26 = call i32 @fs_sexa(i8* %0, double %2, i32 %25, i32 %23)
br label %29
27: ; preds = %3
%28 = call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) %1, double %2)
br label %29
29: ; preds = %27, %22
%30 = phi i32 [ %26, %22 ], [ %28, %27 ]
ret i32 %30
}