#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 /*<<< orphan*/ set_user_timer_countdown(int, long);
int /*<<< orphan*/ sprintf(char *, char *, int, unsigned long, ...);
char *translate_settimer_message(unsigned char *buffer) {
  unsigned long timeout = 0;
  int j, timer;
  static char message[64];
  timer = buffer[2] | (buffer[3] << 8);
  for (j = 0; j < 4; j++)
    timeout |= (unsigned long)(buffer[j + 4] << (8 * j));
  set_user_timer_countdown(timer, (long)timeout);
  if (timeout < 120)
    sprintf(message, "Countdown timer %d set to %ld seconds", timer, timeout);
  else
    sprintf(message, "Countdown timer %d set to %ld:%02ld:%02ld", timer,
            timeout / 3600L, (timeout % 3600L) / 60L, timeout % 3600L % 60L);
  return message;
}


x86 assembly (clang, -O0):
<translate_settimer_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    118e <translate_settimer_message+0x6e>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x14(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
cltq
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1153 <translate_settimer_message+0x33>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <set_user_timer_countdown@plt>
cmpq   $0x78,-0x10(%rbp)
jae    11c6 <translate_settimer_message+0xa6>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0x2e8d(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    1231 <translate_settimer_message+0x111>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    $0xe10,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%rax
mov    $0x3c,%esi
xor    %edx,%edx
div    %rsi
mov    %rax,%r8
mov    -0x10(%rbp),%rax
mov    $0xe10,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%rax
mov    $0x3c,%esi
xor    %edx,%edx
div    %rsi
mov    %rdx,%r9
mov    -0x1c(%rbp),%edx
lea    0x2e1d(%rip),%rdi
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    0x2e08(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<translate_settimer_message>:
push   %rbp
push   %rbx
push   %rax
movzwl 0x4(%rdi),%eax
movzbl 0x6(%rdi),%ecx
shl    $0x10,%rcx
or     %rax,%rcx
movzbl 0x7(%rdi),%eax
shl    $0x18,%eax
movslq %eax,%rbx
or     %rcx,%rbx
movzwl 0x2(%rdi),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <set_user_timer_countdown@plt>
cmp    $0x77,%rbx
ja     116f <translate_settimer_message+0x4f>
lea    0x2ee6(%rip),%rdi
lea    0xe9f(%rip),%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    11be <translate_settimer_message+0x9e>
mov    %rbx,%rax
shr    $0x4,%rax
movabs $0x91a2b3c4d5e6f81,%rcx
2b 1a 09
mul    %rcx
mov    %rdx,%rcx
shr    $0x3,%rcx
imul   $0xe10,%ecx,%eax
sub    %eax,%ebx
imul   $0x8889,%ebx,%r8d
shr    $0x15,%r8d
imul   $0x3c,%r8d,%eax
sub    %eax,%ebx
movzwl %bx,%r9d
lea    0x2e92(%rip),%rdi
lea    0xe71(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0x2e7b(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@translate_settimer_message.message = internal global [64 x i8] zeroinitializer
@.str = [38 x i8] c"Countdown timer %d set to %ld seconds\00"
@.str.1 = [42 x i8] c"Countdown timer %d set to %ld:%02ld:%02ld\00"
define i8* @translate_settimer_message(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i64 0, i64* %3
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 2
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 3
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = shl i32 %13, 8
%15 = or i32 %9, %14
store i32 %15, i32* %5
store i32 0, i32* %4
br label %16
16: ; preds = %33, %1
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 4
br i1 %18, label %19, label %36
19: ; preds = %16
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = load i32, i32* %4
%28 = mul nsw i32 8, %27
%29 = shl i32 %26, %28
%30 = sext i32 %29 to i64
%31 = load i64, i64* %3
%32 = or i64 %31, %30
store i64 %32, i64* %3
br label %33
33: ; preds = %19
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %16
36: ; preds = %16
%37 = load i32, i32* %5
%38 = load i64, i64* %3
%39 = call i32 @set_user_timer_countdown(i32 %37, i64 %38)
%40 = load i64, i64* %3
%41 = icmp ult i64 %40, 120
br i1 %41, label %42, label %46
42: ; preds = %36
%43 = load i32, i32* %5
%44 = load i64, i64* %3
%45 = call i32 (i8*, i8*, i32, i64, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %43, i64 %44)
br label %57
46: ; preds = %36
%47 = load i32, i32* %5
%48 = load i64, i64* %3
%49 = udiv i64 %48, 3600
%50 = load i64, i64* %3
%51 = urem i64 %50, 3600
%52 = udiv i64 %51, 60
%53 = load i64, i64* %3
%54 = urem i64 %53, 3600
%55 = urem i64 %54, 60
%56 = call i32 (i8*, i8*, i32, i64, ...) @sprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %47, i64 %49, i64 %52, i64 %55)
br label %57
57: ; preds = %46, %42
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0)
}

LLVM IR (-O2):
@translate_settimer_message.message = internal global [64 x i8] zeroinitializer
@.str = [38 x i8] c"Countdown timer %d set to %ld seconds\00"
@.str.1 = [42 x i8] c"Countdown timer %d set to %ld:%02ld:%02ld\00"
define i8* @translate_settimer_message(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 2
%3 = load i8, i8* %2
%4 = getelementptr inbounds i8, i8* %0, i64 3
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = shl nuw nsw i32 %6, 8
%8 = getelementptr inbounds i8, i8* %0, i64 4
%9 = load i8, i8* %8
%10 = zext i8 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 5
%12 = load i8, i8* %11
%13 = zext i8 %12 to i64
%14 = shl nuw nsw i64 %13, 8
%15 = or i64 %14, %10
%16 = getelementptr inbounds i8, i8* %0, i64 6
%17 = load i8, i8* %16
%18 = zext i8 %17 to i64
%19 = shl nuw nsw i64 %18, 16
%20 = or i64 %15, %19
%21 = getelementptr inbounds i8, i8* %0, i64 7
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = shl nuw i32 %23, 24
%25 = sext i32 %24 to i64
%26 = or i64 %20, %25
%27 = zext i8 %3 to i32
%28 = or i32 %7, %27
%29 = tail call i32 @set_user_timer_countdown(i32 %28, i64 %26)
%30 = icmp ult i64 %26, 120
br i1 %30, label %31, label %33
31: ; preds = %1
%32 = tail call i32 (i8*, i8*, i32, i64, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %28, i64 %26)
br label %42
33: ; preds = %1
%34 = udiv i64 %26, 3600
%35 = urem i64 %26, 3600
%36 = trunc i64 %35 to i16
%37 = udiv i16 %36, 60
%38 = zext i16 %37 to i64
%39 = urem i16 %36, 60
%40 = zext i16 %39 to i64
%41 = tail call i32 (i8*, i8*, i32, i64, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %28, i64 %34, i64 %38, i64 %40)
br label %42
42: ; preds = %33, %31
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @translate_settimer_message.message, i64 0, i64 0)
}