#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*/ sprintf(char *, char *, int, double);
int /*<<< orphan*/ system(char *);
void pwm(int pin, double val) {
  double angle;
  angle = val / 100.0;
  if (angle < 0.1)
    angle = 0.0;
  else if (angle > 1.0)
    angle = 1.0;
  char str[40];
  sprintf(str, "echo %i=%.3f > /dev/pi-blaster", pin, angle);
  system((char *)str);
}


x86 assembly (clang, -O0):
<pwm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xecb(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeb2(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1166 <pwm+0x46>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118f <pwm+0x6f>
movsd  -0x18(%rbp),%xmm0
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118a <pwm+0x6a>
movsd  0xe8b(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    118f <pwm+0x6f>
lea    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%edx
movsd  -0x18(%rbp),%xmm0
lea    0xe76(%rip),%rsi
call   1040 <sprintf@plt>
lea    -0x40(%rbp),%rdi
call   1030 <system@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwm>:
push   %rbx
sub    $0x30,%rsp
movapd %xmm0,%xmm1
mov    %edi,%edx
divsd  0xecd(%rip),%xmm1
xorpd  %xmm0,%xmm0
movsd  0xec9(%rip),%xmm2
ucomisd %xmm1,%xmm2
ja     115b <pwm+0x3b>
ucomisd 0xec3(%rip),%xmm1
movapd %xmm1,%xmm0
jbe    115b <pwm+0x3b>
movsd  0xeb5(%rip),%xmm0
lea    0xeb6(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [31 x i8] c"echo %i=%.3f > /dev/pi-blaster\00"
define void @pwm(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca double
%6 = alloca [40 x i8]
store i32 %0, i32* %3
store double %1, double* %4
%7 = load double, double* %4
%8 = fdiv double %7, 1.000000e+02
store double %8, double* %5
%9 = load double, double* %5
%10 = fcmp olt double %9, 1.000000e-01
br i1 %10, label %11, label %12
11: ; preds = %2
store double 0.000000e+00, double* %5
br label %17
12: ; preds = %2
%13 = load double, double* %5
%14 = fcmp ogt double %13, 1.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %12
store double 1.000000e+00, double* %5
br label %16
16: ; preds = %15, %12
br label %17
17: ; preds = %16, %11
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %3
%20 = load double, double* %5
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %19, double %20)
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %6, i64 0, i64 0
%23 = call i32 @system(i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"echo %i=%.3f > /dev/pi-blaster\00"
define void @pwm(i32 %0, double %1) {
%3 = alloca [40 x i8]
%4 = fdiv double %1, 1.000000e+02
%5 = fcmp olt double %4, 1.000000e-01
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = fcmp ogt double %4, 1.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %6
br label %9
9: ; preds = %2, %6, %8
%10 = phi double [ 1.000000e+00, %8 ], [ %4, %6 ], [ 0.000000e+00, %2 ]
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %0, double %10)
%13 = call i32 @system(i8* %11)
ret void
}