#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int PWMChannel_enable(char *chnl) {
  int fchnl;
  fchnl = open("/sys/class/pwm/pwmchip0/export", O_WRONLY);
  if (fchnl < 0) {
    fprintf(stderr,
            "Cannot open /sys/class/pwm/pwmchip0/export to export it \n");
    return -1;
  }
  write(fchnl, chnl, 4);
  close(fchnl);
  return 0;
}


x86 assembly (clang, -O0):
<PWMChannel_enable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118f <PWMChannel_enable+0x4f>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <PWMChannel_enable+0x6f>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PWMChannel_enable>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
lea    0xeaa(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     117b <PWMChannel_enable+0x3b>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    1195 <PWMChannel_enable+0x55>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"/sys/class/pwm/pwmchip0/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [58 x i8] c"Cannot open /sys/class/pwm/pwmchip0/export to export it \0A\00"
define i32 @PWMChannel_enable(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i32, i32* @O_WRONLY
%6 = call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %18
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i8*, i8** %3
%15 = call i32 @write(i32 %13, i8* %14, i32 4)
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
store i32 0, i32* %2
br label %18
18: ; preds = %12, %9
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@.str = [31 x i8] c"/sys/class/pwm/pwmchip0/export\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [58 x i8] c"Cannot open /sys/class/pwm/pwmchip0/export to export it \0A\00"
define i32 @PWMChannel_enable(i8* nocapture %0) {
%2 = load i32, i32* @O_WRONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %11
8: ; preds = %1
%9 = tail call i32 @write(i32 %3, i8* %0, i32 4)
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ -1, %5 ], [ 0, %8 ]
ret i32 %12
}