#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*/ printf(char *);
int /*<<< orphan*/ serialCommand(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
int strlen(char *);
void hr20SetTimer(char *timer_string) {
  int day, slot, mode, minutes;
  char buffer[20];
  if (strlen(timer_string) != 7) {
    printf("Wrong format in string!\n");
    return;
  }
  day = timer_string[0] - 48;
  slot = timer_string[1] - 48;
  mode = timer_string[2] - 48;
  if (day < 0 || day > 7) {
    printf("Day must be between 0 and 7\n");
    return;
  }
  if (mode < 0 || mode > 3) {
    printf("Mode must be between 0 and 3\n");
    return;
  }
  minutes = 600 * (timer_string[3] - 48) + 60 * (timer_string[4] - 48) +
            10 * (timer_string[5] - 48) + (timer_string[6] - 48);
  sprintf(buffer, "\rW%d%d%d%03x\r", day, slot, mode, minutes);
  serialCommand(buffer, 0);
}


x86 assembly (clang, -O0):
<hr20SetTimer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x7,%eax
je     116f <hr20SetTimer+0x2f>
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
jmp    124c <hr20SetTimer+0x10c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11ac <hr20SetTimer+0x6c>
cmpl   $0x7,-0xc(%rbp)
jle    11bd <hr20SetTimer+0x7d>
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
jmp    124c <hr20SetTimer+0x10c>
cmpl   $0x0,-0x14(%rbp)
jl     11d1 <hr20SetTimer+0x91>
cmpl   $0x3,-0x14(%rbp)
jle    11e2 <hr20SetTimer+0xa2>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
jmp    124c <hr20SetTimer+0x10c>
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%eax
sub    $0x30,%eax
imul   $0x258,%eax,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x4(%rcx),%ecx
sub    $0x30,%ecx
imul   $0x3c,%ecx,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x5(%rcx),%ecx
sub    $0x30,%ecx
imul   $0xa,%ecx,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x6(%rcx),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
mov    -0x18(%rbp),%r9d
lea    0xe18(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1050 <serialCommand@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hr20SetTimer>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x7,%eax
jne    1165 <hr20SetTimer+0x25>
movsbl (%rbx),%edx
lea    -0x38(%rdx),%eax
cmp    $0xf7,%al
ja     116e <hr20SetTimer+0x2e>
lea    0xec8(%rip),%rdi
jmp    1182 <hr20SetTimer+0x42>
lea    0xedb(%rip),%rdi
jmp    1182 <hr20SetTimer+0x42>
movsbl 0x2(%rbx),%r8d
lea    -0x34(%r8),%eax
cmp    $0xfb,%al
ja     118c <hr20SetTimer+0x4c>
lea    0xe8c(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1030 <puts@plt>
add    $0xffffffd0,%edx
movsbl 0x1(%rbx),%ecx
add    $0xffffffd0,%ecx
add    $0xffffffd0,%r8d
movsbl 0x3(%rbx),%eax
imul   $0x258,%eax,%eax
movsbl 0x4(%rbx),%esi
imul   $0x3c,%esi,%esi
add    %eax,%esi
movsbl 0x5(%rbx),%eax
lea    (%rax,%rax,4),%eax
movsbl 0x6(%rbx),%edi
lea    (%rsi,%rax,2),%eax
lea    -0x7dd0(%rdi,%rax,1),%r9d
ff
lea    0xe36(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <serialCommand@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Wrong format in string!\0A\00"
@.str.1 = [29 x i8] c"Day must be between 0 and 7\0A\00"
@.str.2 = [30 x i8] c"Mode must be between 0 and 3\0A\00"
@.str.3 = [14 x i8] c"\0DW%d%d%d%03x\0D\00"
define void @hr20SetTimer(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [20 x i8]
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp ne i32 %9, 7
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %79
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = sub nsw i32 %17, 48
store i32 %18, i32* %3
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
store i32 %23, i32* %4
%24 = load i8*, i8** %2
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = sub nsw i32 %27, 48
store i32 %28, i32* %5
%29 = load i32, i32* %3
%30 = icmp slt i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %13
%32 = load i32, i32* %3
%33 = icmp sgt i32 %32, 7
br i1 %33, label %34, label %36
34: ; preds = %31, %13
%35 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %79
36: ; preds = %31
%37 = load i32, i32* %5
%38 = icmp slt i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %5
%41 = icmp sgt i32 %40, 3
br i1 %41, label %42, label %44
42: ; preds = %39, %36
%43 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %79
44: ; preds = %39
%45 = load i8*, i8** %2
%46 = getelementptr inbounds i8, i8* %45, i64 3
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = sub nsw i32 %48, 48
%50 = mul nsw i32 600, %49
%51 = load i8*, i8** %2
%52 = getelementptr inbounds i8, i8* %51, i64 4
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = sub nsw i32 %54, 48
%56 = mul nsw i32 60, %55
%57 = add nsw i32 %50, %56
%58 = load i8*, i8** %2
%59 = getelementptr inbounds i8, i8* %58, i64 5
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = sub nsw i32 %61, 48
%63 = mul nsw i32 10, %62
%64 = add nsw i32 %57, %63
%65 = load i8*, i8** %2
%66 = getelementptr inbounds i8, i8* %65, i64 6
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = sub nsw i32 %68, 48
%70 = add nsw i32 %64, %69
store i32 %70, i32* %6
%71 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%72 = load i32, i32* %3
%73 = load i32, i32* %4
%74 = load i32, i32* %5
%75 = load i32, i32* %6
%76 = call i32 @sprintf(i8* %71, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %72, i32 %73, i32 %74, i32 %75)
%77 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%78 = call i32 @serialCommand(i8* %77, i32 0)
br label %79
79: ; preds = %44, %42, %34, %11
ret void
}

LLVM IR (-O2):
@.str.3 = [14 x i8] c"\0DW%d%d%d%03x\0D\00"
@str = [29 x i8] c"Mode must be between 0 and 3\00"
@str.4 = [28 x i8] c"Day must be between 0 and 7\00"
@str.5 = [24 x i8] c"Wrong format in string!\00"
define void @hr20SetTimer(i8* %0) {
%2 = alloca [20 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp eq i32 %4, 7
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
br label %51
8: ; preds = %1
%9 = load i8, i8* %0
%10 = sext i8 %9 to i32
%11 = add nsw i32 %10, -48
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = add nsw i32 %14, -48
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = add nsw i32 %18, -48
%20 = add i8 %9, -56
%21 = icmp ult i8 %20, -8
br i1 %21, label %22, label %24
22: ; preds = %8
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.4, i64 0, i64 0))
br label %51
24: ; preds = %8
%25 = add i8 %17, -52
%26 = icmp ult i8 %25, -4
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %51
29: ; preds = %24
%30 = getelementptr inbounds i8, i8* %0, i64 3
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = mul nsw i32 %32, 600
%34 = getelementptr inbounds i8, i8* %0, i64 4
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = mul nsw i32 %36, 60
%38 = getelementptr inbounds i8, i8* %0, i64 5
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = mul nsw i32 %40, 10
%42 = getelementptr inbounds i8, i8* %0, i64 6
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = add nsw i32 %33, -32208
%46 = add nsw i32 %45, %37
%47 = add nsw i32 %46, %41
%48 = add nsw i32 %47, %44
%49 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %15, i32 %19, i32 %48)
%50 = call i32 @serialCommand(i8* %3, i32 0)
br label %51
51: ; preds = %29, %27, %22, %6
ret void
}