#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ asprintf(char **, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
void set_only_pwm(int pwm, unsigned long t_high, unsigned long period) {
  char *path;
  FILE *fptr;
  if (t_high < 360000)
    t_high = 360000;
  if (t_high > 1900000)
    t_high = 1900000;
  printf("New Thigh = %lu\n", t_high);
  asprintf(&path, "/sys/class/pwm/pwmchip0/pwm%d/enable", pwm);
  fptr = fopen(path, "w");
  fprintf(fptr, "0");
  fclose(fptr);
  free(path);
  asprintf(&path, "/sys/class/pwm/pwmchip0/pwm%d/duty_cycle", pwm);
  fptr = fopen(path, "w");
  fprintf(fptr, "%lu", t_high);
  fclose(fptr);
  free(path);
  asprintf(&path, "/sys/class/pwm/pwmchip0/pwm%d/period", pwm);
  fptr = fopen(path, "w");
  fprintf(fptr, "%lu", period);
  fclose(fptr);
  free(path);
  asprintf(&path, "/sys/class/pwm/pwmchip0/pwm%d/enable", pwm);
  fptr = fopen(path, "w");
  fprintf(fptr, "1");
  fclose(fptr);
  free(path);
}


x86 assembly (clang, -O0):
<set_only_pwm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x57e40,-0x10(%rbp)
jae    1189 <set_only_pwm+0x29>
movq   $0x57e40,-0x10(%rbp)
cmpq   $0x1cfde0,-0x10(%rbp)
jbe    119f <set_only_pwm+0x3f>
movq   $0x1cfde0,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%edx
lea    -0x20(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edx
lea    -0x20(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edx
lea    -0x20(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edx
lea    -0x20(%rbp),%rdi
lea    0xd6b(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_only_pwm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %edi,%r14d
cmp    $0x57e41,%rsi
mov    $0x57e40,%eax
cmovae %rsi,%rax
cmp    $0x1cfde0,%rax
mov    $0x1cfde0,%ebp
cmovb  %rax,%rbp
lea    0xe54(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
lea    0xe56(%rip),%rsi
lea    0x8(%rsp),%r12
mov    %r12,%rdi
mov    %r14d,%edx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdi
lea    0xe5f(%rip),%r13
mov    %r13,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0x30,%edi
mov    %rax,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xe30(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe37(%rip),%r15
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
lea    0xe12(%rip),%rsi
mov    %r12,%rdi
mov    %r14d,%edx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
lea    0xd75(%rip),%rsi
mov    %r14d,%edx
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0x31,%edi
mov    %rax,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"New Thigh = %lu\0A\00"
@.str.1 = [37 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/enable\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [2 x i8] c"0\00"
@.str.4 = [41 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/duty_cycle\00"
@.str.5 = [4 x i8] c"%lu\00"
@.str.6 = [37 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/period\00"
@.str.7 = [2 x i8] c"1\00"
define void @set_only_pwm(i32 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32*
store i32 %0, i32* %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %5
%10 = icmp ult i64 %9, 360000
br i1 %10, label %11, label %12
11: ; preds = %3
store i64 360000, i64* %5
br label %12
12: ; preds = %11, %3
%13 = load i64, i64* %5
%14 = icmp ugt i64 %13, 1900000
br i1 %14, label %15, label %16
15: ; preds = %12
store i64 1900000, i64* %5
br label %16
16: ; preds = %15, %12
%17 = load i64, i64* %5
%18 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %17)
%19 = load i32, i32* %4
%20 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %7
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %22, i32** %8
%23 = load i32*, i32** %8
%24 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32*, i32** %8
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %7
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* %4
%30 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %7
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %32, i32** %8
%33 = load i32*, i32** %8
%34 = load i64, i64* %5
%35 = call i32 (i32*, i8*, ...) @fprintf(i32* %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %34)
%36 = load i32*, i32** %8
%37 = call i32 @fclose(i32* %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
%40 = load i32, i32* %4
%41 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %40)
%42 = load i8*, i8** %7
%43 = call i32* @fopen(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %43, i32** %8
%44 = load i32*, i32** %8
%45 = load i64, i64* %6
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %45)
%47 = load i32*, i32** %8
%48 = call i32 @fclose(i32* %47)
%49 = load i8*, i8** %7
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %4
%52 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %51)
%53 = load i8*, i8** %7
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %54, i32** %8
%55 = load i32*, i32** %8
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%57 = load i32*, i32** %8
%58 = call i32 @fclose(i32* %57)
%59 = load i8*, i8** %7
%60 = call i32 @free(i8* %59)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"New Thigh = %lu\0A\00"
@.str.1 = [37 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/enable\00"
@.str.2 = [2 x i8] c"w\00"
@.str.4 = [41 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/duty_cycle\00"
@.str.5 = [4 x i8] c"%lu\00"
@.str.6 = [37 x i8] c"/sys/class/pwm/pwmchip0/pwm%d/period\00"
define void @set_only_pwm(i32 %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp ugt i64 %1, 360000
%7 = select i1 %6, i64 %1, i64 360000
%8 = icmp ult i64 %7, 1900000
%9 = select i1 %8, i64 %7, i64 1900000
%10 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @fputc(i32 48, i32* %13)
%15 = call i32 @fclose(i32* %13)
%16 = load i8*, i8** %4
%17 = call i32 @free(i8* %16)
%18 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %0)
%19 = load i8*, i8** %4
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %9)
%22 = call i32 @fclose(i32* %20)
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i32 %0)
%26 = load i8*, i8** %4
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (i32*, i8*, ...) @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i64 %2)
%29 = call i32 @fclose(i32* %27)
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
%32 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%33 = load i8*, i8** %4
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @fputc(i32 49, i32* %34)
%36 = call i32 @fclose(i32* %34)
%37 = load i8*, i8** %4
%38 = call i32 @free(i8* %37)
ret void
}