#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 */
char *Cmd_SkipChars(char *);
char *Cmd_SkipSpace(char *);
int /*<<< orphan*/ PWM_SetDutyCycle(unsigned char, int);
int /*<<< orphan*/ U1_TxPuts(char *);
int /*<<< orphan*/ U3_TxPuts(char *);
void *atoi(char *);
int /*<<< orphan*/ csprintf(char *, char *, unsigned char, int);
int Update_Pwm(char *buf) {
  char cmd[50];
  unsigned char ch;
  int duty;
  if (buf == NULL)
    return -1;
  buf = Cmd_SkipSpace(buf);
  ch = atoi(buf);
  buf = Cmd_SkipSpace(Cmd_SkipChars(buf));
  duty = atoi(buf);
  csprintf(cmd, "pwm: %d %d\r\n", ch, duty);
  U1_TxPuts(cmd);
  if (ch >= 8) {
    csprintf(cmd, "pwm: %d %d\r\n", ch - 8, duty);
    U3_TxPuts(cmd);
  } else
    PWM_SetDutyCycle(ch, duty);
  return 0;
}


x86 assembly (clang, -O0):
<Update_Pwm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <Update_Pwm+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <Update_Pwm+0xcc>
mov    -0x10(%rbp),%rdi
call   1080 <Cmd_SkipSpace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %al,-0x51(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <Cmd_SkipChars@plt>
mov    %rax,%rdi
call   1080 <Cmd_SkipSpace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x58(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x51(%rbp),%al
mov    -0x58(%rbp),%ecx
lea    0xe22(%rip),%rsi
movzbl %al,%edx
call   1030 <csprintf@plt>
lea    -0x50(%rbp),%rdi
call   1040 <U1_TxPuts@plt>
movzbl -0x51(%rbp),%eax
cmp    $0x8,%eax
jl     1227 <Update_Pwm+0xb7>
lea    -0x50(%rbp),%rdi
movzbl -0x51(%rbp),%eax
sub    $0x8,%eax
mov    -0x58(%rbp),%ecx
lea    0xdef(%rip),%rsi
movzbl %al,%edx
call   1030 <csprintf@plt>
lea    -0x50(%rbp),%rdi
call   1050 <U3_TxPuts@plt>
jmp    1235 <Update_Pwm+0xc5>
mov    -0x51(%rbp),%al
mov    -0x58(%rbp),%esi
movzbl %al,%edi
call   1060 <PWM_SetDutyCycle@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Update_Pwm>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
test   %rdi,%rdi
je     11f9 <Update_Pwm+0x89>
call   1080 <Cmd_SkipSpace@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1090 <Cmd_SkipChars@plt>
mov    %rax,%rdi
call   1080 <Cmd_SkipSpace@plt>
mov    %rax,%rdi
call   1070 <atoi@plt>
mov    %rax,%r14
movzbl %r15b,%edx
lea    0xe49(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14d,%ecx
call   1030 <csprintf@plt>
mov    %rbx,%rdi
call   1040 <U1_TxPuts@plt>
test   $0xf8,%r15b
je     1200 <Update_Pwm+0x90>
lea    -0x8(%r15),%eax
movzbl %al,%edx
lea    0xe1f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14d,%ecx
call   1030 <csprintf@plt>
mov    %rbx,%rdi
call   1050 <U3_TxPuts@plt>
jmp    120c <Update_Pwm+0x9c>
mov    $0xffffffff,%eax
jmp    120e <Update_Pwm+0x9e>
movzbl %r15b,%edi
mov    %r14d,%esi
call   1060 <PWM_SetDutyCycle@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"pwm: %d %d\0D\0A\00"
define i32 @Update_Pwm(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [50 x i8]
%5 = alloca i8
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 -1, i32* %2
br label %46
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i8* @Cmd_SkipSpace(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = call i8* @atoi(i8* %13)
%15 = ptrtoint i8* %14 to i8
store i8 %15, i8* %5
%16 = load i8*, i8** %3
%17 = call i8* @Cmd_SkipChars(i8* %16)
%18 = call i8* @Cmd_SkipSpace(i8* %17)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = call i8* @atoi(i8* %19)
%21 = ptrtoint i8* %20 to i32
store i32 %21, i32* %6
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%23 = load i8, i8* %5
%24 = load i32, i32* %6
%25 = call i32 @csprintf(i8* %22, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %23, i32 %24)
%26 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%27 = call i32 @U1_TxPuts(i8* %26)
%28 = load i8, i8* %5
%29 = zext i8 %28 to i32
%30 = icmp sge i32 %29, 8
br i1 %30, label %31, label %41
31: ; preds = %10
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%33 = load i8, i8* %5
%34 = zext i8 %33 to i32
%35 = sub nsw i32 %34, 8
%36 = trunc i32 %35 to i8
%37 = load i32, i32* %6
%38 = call i32 @csprintf(i8* %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %36, i32 %37)
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%40 = call i32 @U3_TxPuts(i8* %39)
br label %45
41: ; preds = %10
%42 = load i8, i8* %5
%43 = load i32, i32* %6
%44 = call i32 @PWM_SetDutyCycle(i8 zeroext %42, i32 %43)
br label %45
45: ; preds = %41, %31
store i32 0, i32* %2
br label %46
46: ; preds = %45, %9
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
@.str = [13 x i8] c"pwm: %d %d\0D\0A\00"
define i32 @Update_Pwm(i8* %0) {
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = icmp eq i8* %0, null
br i1 %4, label %25, label %5
5: ; preds = %1
%6 = tail call i8* @Cmd_SkipSpace(i8* %0)
%7 = tail call i8* @atoi(i8* %6)
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i8
%10 = tail call i8* @Cmd_SkipChars(i8* %6)
%11 = tail call i8* @Cmd_SkipSpace(i8* %10)
%12 = tail call i8* @atoi(i8* %11)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i32
%15 = call i32 @csprintf(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %9, i32 %14)
%16 = call i32 @U1_TxPuts(i8* %3)
%17 = and i64 %8, 248
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %5
%20 = add i8 %9, -8
%21 = call i32 @csprintf(i8* %3, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %20, i32 %14)
%22 = call i32 @U3_TxPuts(i8* %3)
br label %25
23: ; preds = %5
%24 = call i32 @PWM_SetDutyCycle(i8 zeroext %9, i32 %14)
br label %25
25: ; preds = %19, %23, %1
%26 = phi i32 [ -1, %1 ], [ 0, %23 ], [ 0, %19 ]
ret i32 %26
}