#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_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int get_led_duty(int channel) {
  int fd;
  int density;
  char file[100];
  char str_density[10];
  printf("file: /sys/class/pwm/gpio_pwm:%d/duty_ns\n", channel);
  sprintf(file, "/sys/class/pwm/gpio_pwm:%d/duty_ns", channel);
  fd = open(file, O_RDONLY);
  read(fd, str_density, 10);
  close(fd);
  sscanf(str_density, "%3d0000", &density);
  printf("density: %d\n", density);
  return density;
}


x86 assembly (clang, -O0):
<get_led_duty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe9f(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x7a(%rbp),%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    -0x7a(%rbp),%rdi
lea    0xe84(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0xc(%rbp),%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_led_duty>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %edi,%ebx
lea    0xe90(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
lea    0xeac(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1080 <sprintf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0x6(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <read@plt>
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe8b(%rip),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1060 <sscanf@plt>
mov    (%rsp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
mov    (%rsp),%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

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

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