#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);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void setDutyCyclePercentForOutput(int percent, int fd) {
  char command[5];
  int newDuty = (1.0e9 / 10000) - ((percent / 100.0) * (1.0e9 / 10000));
  if (newDuty > (1.0e9 / 10000) || newDuty < 0) {
    printf("ERROR: Invalid duty cycle: %d", newDuty);
    return;
  }
  sprintf(command, "%d", newDuty);
  write(fd, command, strlen(command));
}


x86 assembly (clang, -O0):
<setDutyCyclePercentForOutput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  0xead(%rip),%xmm1
divsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xe82(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     11ae <setDutyCyclePercentForOutput+0x6e>
cmpl   $0x0,-0x14(%rbp)
jge    11c2 <setDutyCyclePercentForOutput+0x82>
mov    -0x14(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
jmp    11fa <setDutyCyclePercentForOutput+0xba>
lea    -0xd(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe5b(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0xd(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0xd(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setDutyCyclePercentForOutput>:
push   %r14
push   %rbx
push   %rax
cvtsi2sd %edi,%xmm0
divsd  0xeb0(%rip),%xmm0
movsd  0xeb0(%rip),%xmm1
mulsd  %xmm1,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
cmp    $0x186a1,%edx
jb     1181 <setDutyCyclePercentForOutput+0x41>
lea    0xe9d(%rip),%rdi
mov    %edx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <printf@plt>
mov    %esi,%ebx
lea    0xea1(%rip),%rsi
lea    0x3(%rsp),%r14
mov    %r14,%rdi
call   1060 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [30 x i8] c"ERROR: Invalid duty cycle: %d\00"
@.str.1 = [3 x i8] c"%d\00"
define void @setDutyCyclePercentForOutput(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [5 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 1.000000e+02
%10 = fneg double %9
%11 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+05, double 1.000000e+05)
%12 = fptosi double %11 to i32
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = sitofp i32 %13 to double
%15 = fcmp ogt double %14, 1.000000e+05
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16, %2
%20 = load i32, i32* %6
%21 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %31
22: ; preds = %16
%23 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%24 = load i32, i32* %6
%25 = call i32 @sprintf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %4
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @write(i32 %26, i8* %27, i32 %29)
br label %31
31: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"ERROR: Invalid duty cycle: %d\00"
@.str.1 = [3 x i8] c"%d\00"
define void @setDutyCyclePercentForOutput(i32 %0, i32 %1) {
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%5 = sitofp i32 %0 to double
%6 = fdiv double %5, -1.000000e+02
%7 = tail call double @llvm.fmuladd.f64(double %6, double 1.000000e+05, double 1.000000e+05)
%8 = fptosi double %7 to i32
%9 = icmp ugt i32 %8, 100000
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %16
12: ; preds = %2
%13 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @write(i32 %1, i8* %4, i32 %14)
br label %16
16: ; preds = %12, %10
ret void
}