#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ pwm_enable();
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int pwm_enable_pin(const char *pin) {
  if (pwm_enable() < 0)
    return -1;
  int fd;
  if ((fd = open("/sys/devices/bone_capemgr.8/slots", O_WRONLY)) < 0)
    return -1;
  char bone_pwm_pin[15];
  snprintf(bone_pwm_pin, 15, "bone_pwm_%s", pin);
  write(fd, bone_pwm_pin, strlen(bone_pwm_pin));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<pwm_enable_pin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <pwm_enable@plt>
cmp    $0x0,%rax
jge    1189 <pwm_enable_pin+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <pwm_enable_pin+0xa3>
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11b6 <pwm_enable_pin+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <pwm_enable_pin+0xa3>
lea    -0x23(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0xf,%esi
lea    0xe58(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    -0x23(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x23(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pwm_enable_pin>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <pwm_enable@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     11d0 <pwm_enable_pin+0x70>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe74(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11d0 <pwm_enable_pin+0x70>
mov    %eax,%ebp
lea    0xe84(%rip),%rdx
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xf,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"/sys/devices/bone_capemgr.8/slots\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"bone_pwm_%s\00"
define i32 @pwm_enable_pin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [15 x i8]
store i8* %0, i8** %3
%6 = call i64 (...) @pwm_enable()
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %25
9: ; preds = %1
%10 = load i32, i32* @O_WRONLY
%11 = call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 %11, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9
store i32 -1, i32* %2
br label %25
14: ; preds = %9
%15 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = call i32 @snprintf(i8* %15, i32 15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i32, i32* %4
%19 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [15 x i8], [15 x i8]* %5, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
%22 = call i32 @write(i32 %18, i8* %19, i32 %21)
%23 = load i32, i32* %4
%24 = call i32 @close(i32 %23)
store i32 0, i32* %2
br label %25
25: ; preds = %14, %13, %8
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [34 x i8] c"/sys/devices/bone_capemgr.8/slots\00"
@O_WRONLY = global i32 0
@.str.1 = [12 x i8] c"bone_pwm_%s\00"
define i32 @pwm_enable_pin(i8* %0) {
%2 = alloca [15 x i8]
%3 = tail call i64 (...) @pwm_enable()
%4 = icmp slt i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = load i32, i32* @O_WRONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%11 = call i32 @snprintf(i8* %10, i32 15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = call i32 @strlen(i8* %10)
%13 = call i32 @write(i32 %7, i8* %10, i32 %12)
%14 = call i32 @close(i32 %7)
br label %15
15: ; preds = %9, %5, %1
%16 = phi i32 [ -1, %1 ], [ 0, %9 ], [ -1, %5 ]
ret i32 %16
}