#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*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strcat(char *, char *);
int SetPWMPeriod(int PWM_num, int period) {
  FILE *PWM_period_addr;
  char PWM_pin_num[5];
  char PWM_addr[60] = "/sys/class/pwm/pwm";
  sprintf(PWM_pin_num, "%i", PWM_num);
  strcat(strcat(PWM_addr, PWM_pin_num), "/period_ns");
  PWM_period_addr = fopen(PWM_addr, "w");
  if (PWM_period_addr == NULL)
    printf("PWM Period failed to open\n");
  fseek(PWM_period_addr, 0, SEEK_SET);
  fprintf(PWM_period_addr, "%d", period);
  printf("%d > %s\n", period, PWM_addr);
  fflush(PWM_period_addr);
  fclose(PWM_period_addr);
  return 0;
}


x86 assembly (clang, -O0):
<SetPWMPeriod>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x3c,%edx
call   1060 <memcpy@plt>
lea    -0x15(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe7b(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x15(%rbp),%rsi
call   10a0 <strcat@plt>
mov    %rax,%rdi
lea    0xe62(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x60(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120f <SetPWMPeriod+0x7f>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xe26(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetPWMPeriod>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %esi,%r14d
mov    %edi,%edx
movups 0xe78(%rip),%xmm0
movups %xmm0,0x3c(%rsp)
movaps 0xe60(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe44(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe28(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xe58(%rip),%rsi
lea    0xb(%rsp),%rbx
mov    %rbx,%rdi
call   10c0 <sprintf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10b0 <strcat@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
movabs $0x5f646f697265702f,%rcx
6f 64 5f
mov    %rcx,0x10(%rsp,%rax,1)
movl   $0x736e5f,0x17(%rsp,%rax,1)
lea    0xe23(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1243 <SetPWMPeriod+0xa3>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
lea    0xdef(%rip),%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1070 <fprintf@plt>
lea    0xde0(%rip),%rdi
lea    0x10(%rsp),%rdx
mov    %r14d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.SetPWMPeriod.PWM_addr = [60 x i8] c"/sys/class/pwm/pwm\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"%i\00"
@.str.1 = [11 x i8] c"/period_ns\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"PWM Period failed to open\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [9 x i8] c"%d > %s\0A\00"
define i32 @SetPWMPeriod(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [5 x i8]
%7 = alloca [60 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = bitcast [60 x i8]* %7 to i8*
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* %3
%11 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%14 = call i8* @strcat(i8* %12, i8* %13)
%15 = call i8* @strcat(i8* %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = load i32*, i32** %5
%24 = load i32, i32* @SEEK_SET
%25 = call i32 @fseek(i32* %23, i32 0, i32 %24)
%26 = load i32*, i32** %5
%27 = load i32, i32* %4
%28 = call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %4
%30 = getelementptr inbounds [60 x i8], [60 x i8]* %7, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %29, i8* %30)
%32 = load i32*, i32** %5
%33 = call i32 @fflush(i32* %32)
%34 = load i32*, i32** %5
%35 = call i32 @fclose(i32* %34)
ret i32 0
}

LLVM IR (-O2):
@__const.SetPWMPeriod.PWM_addr = [60 x i8] c"/sys/class/pwm/pwm\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [3 x i8] c"%i\00"
@.str.1 = [11 x i8] c"/period_ns\00"
@.str.2 = [2 x i8] c"w\00"
@SEEK_SET = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [9 x i8] c"%d > %s\0A\00"
@str = [26 x i8] c"PWM Period failed to open\00"
define i32 @SetPWMPeriod(i32 %0, i32 %1) {
%3 = alloca [5 x i8]
%4 = alloca [60 x i8]
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [60 x i8], [60 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i8* @strcat(i8* %6, i8* %5)
%9 = call i64 @strlen(i8* %6)
%10 = getelementptr [60 x i8], [60 x i8]* %4, i64 0, i64 %9
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %11, i32 0, i32 %16)
%18 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %1, i8* %6)
%20 = call i32 @fflush(i32* %11)
%21 = call i32 @fclose(i32* %11)
ret i32 0
}