#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*/ assert(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void write_pwm(int pwm_fd, double percent) {
  assert(pwm_fd > 0);
  assert(percent >= 0);
  assert(percent <= 100.0);
  int value = (percent / 100.0) * (double)(1000);
  char buf[5];
  snprintf(buf, 5, "%d", value);
  write(pwm_fd, buf, strlen(buf));
}


x86 assembly (clang, -O0):
<write_pwm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movsd  0xe86(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe53(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x5,%esi
lea    0xe45(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x19(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x19(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pwm>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %edi,%ebp
xor    %edi,%edi
test   %ebp,%ebp
setg   %dil
call   1060 <assert@plt>
xorpd  %xmm0,%xmm0
xor    %edi,%edi
movsd  0x8(%rsp),%xmm1
ucomisd %xmm0,%xmm1
setae  %dil
call   1060 <assert@plt>
movsd  0xe84(%rip),%xmm0
xor    %edi,%edi
ucomisd 0x8(%rsp),%xmm0
setae  %dil
call   1060 <assert@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xe65(%rip),%xmm0
mulsd  0xe65(%rip),%xmm0
cvttsd2si %xmm0,%ecx
lea    0xe62(%rip),%rdx
lea    0x13(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define void @write_pwm(i32 %0, double %1) {
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca [5 x i8]
store i32 %0, i32* %3
store double %1, double* %4
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load double, double* %4
%12 = fcmp oge double %11, 0.000000e+00
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load double, double* %4
%16 = fcmp ole double %15, 1.000000e+02
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = load double, double* %4
%20 = fdiv double %19, 1.000000e+02
%21 = fmul double %20, 1.000000e+03
%22 = fptosi double %21 to i32
store i32 %22, i32* %5
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%24 = load i32, i32* %5
%25 = call i32 @snprintf(i8* %23, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %3
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 %26, i8* %27, i32 %29)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define void @write_pwm(i32 %0, double %1) {
%3 = alloca [5 x i8]
%4 = icmp sgt i32 %0, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = fcmp oge double %1, 0.000000e+00
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = fcmp ole double %1, 1.000000e+02
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = fdiv double %1, 1.000000e+02
%14 = fmul double %13, 1.000000e+03
%15 = fptosi double %14 to i32
%16 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%17 = call i32 @snprintf(i8* %16, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %15)
%18 = call i32 @strlen(i8* %16)
%19 = call i32 @write(i32 %0, i8* %16, i32 %18)
ret void
}