#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*/ ptr;

/* Variables and functions */
int bbb_getPwmPeriod(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
char *bbb_getPwmHz(int header, int pin) {
  static char ptr[128];
  if (header > 0 && pin > 0) {
    int time = bbb_getPwmPeriod(header, pin);
    memset(ptr, 0, sizeof(ptr));
    snprintf(ptr, sizeof(ptr), "%dHz", (int)(1000000000 / time));
    return ptr;
  }
  return "undefined";
}


x86 assembly (clang, -O0):
<bbb_getPwmHz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    11a6 <bbb_getPwmHz+0x76>
cmpl   $0x0,-0x10(%rbp)
jle    11a6 <bbb_getPwmHz+0x76>
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
call   1030 <bbb_getPwmPeriod@plt>
mov    %eax,-0x14(%rbp)
lea    0x2ee9(%rip),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    $0x3b9aca00,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
lea    0x2ecb(%rip),%rdi
mov    $0x80,%esi
lea    0xe6f(%rip),%rdx
call   1040 <snprintf@plt>
lea    0x2eb3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11b1 <bbb_getPwmHz+0x81>
lea    0xe58(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bbb_getPwmHz>:
push   %rbp
push   %rbx
push   %rax
lea    0xecb(%rip),%rbx
test   %edi,%edi
jle    117e <bbb_getPwmHz+0x4e>
test   %esi,%esi
jle    117e <bbb_getPwmHz+0x4e>
call   1030 <bbb_getPwmPeriod@plt>
mov    %eax,%ebp
lea    0x2f00(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
mov    $0x3b9aca00,%eax
xor    %edx,%edx
idiv   %ebp
lea    0xe91(%rip),%rdx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %eax,%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@bbb_getPwmHz.ptr = internal global [128 x i8] zeroinitializer
@.str = [5 x i8] c"%dHz\00"
@.str.1 = [10 x i8] c"undefined\00"
define i8* @bbb_getPwmHz(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %2
%10 = load i32, i32* %5
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @bbb_getPwmPeriod(i32 %13, i32 %14)
store i32 %15, i32* %6
%16 = call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), i32 0, i32 128)
%17 = load i32, i32* %6
%18 = sdiv i32 1000000000, %17
%19 = call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %18)
store i8* getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), i8** %3
br label %21
20: ; preds = %9, %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %21
21: ; preds = %20, %12
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@bbb_getPwmHz.ptr = internal global [128 x i8] zeroinitializer
@.str = [5 x i8] c"%dHz\00"
@.str.1 = [10 x i8] c"undefined\00"
define i8* @bbb_getPwmHz(i32 %0, i32 %1) {
%3 = icmp sgt i32 %0, 0
%4 = icmp sgt i32 %1, 0
%5 = and i1 %3, %4
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = tail call i32 @bbb_getPwmPeriod(i32 %0, i32 %1)
%8 = tail call i32 @memset(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), i32 0, i32 128)
%9 = sdiv i32 1000000000, %7
%10 = tail call i32 @snprintf(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), i32 128, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %11
11: ; preds = %2, %6
%12 = phi i8* [ getelementptr inbounds ([128 x i8], [128 x i8]* @bbb_getPwmHz.ptr, i64 0, i64 0), %6 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %2 ]
ret i8* %12
}