#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*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void led(int channel, int density) {
  int fd;
  char file[100];
  char str_density[10];
  printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", channel);
  printf("density: %d\n", density);
  sprintf(file, "/sys/class/pwm/gpio_pwm:%d/duty_ns", channel);
  sprintf(str_density, "%d0000", density);
  fd = open(file, O_WRONLY);
  write(fd, str_density, strlen(str_density));
  close(fd);
}


x86 assembly (clang, -O0):
<led>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe85(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9a(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x7a(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xeaa(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8c(%rbp)
lea    -0x7a(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x7a(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0xc(%rbp),%edi
call   1060 <close@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<led>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xe8a(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
lea    0xea6(%rip),%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
lea    0xea5(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1080 <sprintf@plt>
lea    0xeb2(%rip),%rsi
lea    0x6(%rsp),%rbp
mov    %rbp,%rdi
mov    %ebx,%edx
call   1080 <sprintf@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <close@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"file: /sys/class/pwm/gpio_pwm:%d/duty_ns\0A\00"
@.str.1 = [13 x i8] c"density: %d\0A\00"
@.str.2 = [35 x i8] c"/sys/class/pwm/gpio_pwm:%d/duty_ns\00"
@.str.3 = [7 x i8] c"%d0000\00"
@O_WRONLY = global i32 0
define void @led(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i8]
%7 = alloca [10 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* %3
%14 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%16 = load i32, i32* %4
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @O_WRONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %5
%21 = load i32, i32* %5
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"file: /sys/class/pwm/gpio_pwm:%d/duty_ns\0A\00"
@.str.1 = [13 x i8] c"density: %d\0A\00"
@.str.2 = [35 x i8] c"/sys/class/pwm/gpio_pwm:%d/duty_ns\00"
@.str.3 = [7 x i8] c"%d0000\00"
@O_WRONLY = global i32 0
define void @led(i32 %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [10 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%9 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%10 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%11 = load i32, i32* @O_WRONLY
%12 = call i32 @open(i8* %5, i32 %11)
%13 = call i32 @strlen(i8* %6)
%14 = call i32 @write(i32 %12, i8* %6, i32 %13)
%15 = call i32 @close(i32 %12)
ret void
}