#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*/ SNDCTL_DSP_SETFRAGMENT;
int /*<<< orphan*/ err_die(char *, ...);
int /*<<< orphan*/ errno;
int ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void set_au_blksz(int audio_fd, int fragsz_arg) {
  int arg = 0x7fff0000;
  for (; fragsz_arg > 1; fragsz_arg /= 2) {
    arg += 1;
    if (fragsz_arg % 2 != 0) {
      err_die("BUG: fragsz_arg to SNDCTL_DSP_SETFRAGMENT not a power of "
              "two\n");
    }
  }
  if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &arg) == -1)
    err_die("BUG: SNDCTL_DSP_SETFRAGMENT ioctl failed: %s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<set_au_blksz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x7fff0000,-0xc(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1192 <set_au_blksz+0x62>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     117a <set_au_blksz+0x4a>
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1040 <err_die@plt>
jmp    117f <set_au_blksz+0x4f>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1145 <set_au_blksz+0x15>
mov    -0x4(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11ce <set_au_blksz+0x9e>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1040 <err_die@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_au_blksz>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    $0x7fff0000,%ebx
cmp    $0x2,%esi
jl     1180 <set_au_blksz+0x50>
mov    %esi,%ebp
mov    $0x7fff0000,%ebx
lea    0xeae(%rip),%r15
jmp    116e <set_au_blksz+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%eax
shr    %eax
add    $0x1,%ebx
cmp    $0x3,%ebp
mov    %eax,%ebp
jbe    1180 <set_au_blksz+0x50>
test   $0x1,%bpl
je     1160 <set_au_blksz+0x30>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <err_die@plt>
jmp    1160 <set_au_blksz+0x30>
mov    %ebx,0x4(%rsp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %r14d,%edi
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11bd <set_au_blksz+0x8d>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe8a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <err_die@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [62 x i8] c"BUG: fragsz_arg to SNDCTL_DSP_SETFRAGMENT not a power of two\0A\00"
@SNDCTL_DSP_SETFRAGMENT = global i32 0
@.str.1 = [46 x i8] c"BUG: SNDCTL_DSP_SETFRAGMENT ioctl failed: %s\0A\00"
@errno = global i32 0
define void @set_au_blksz(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 2147418112, i32* %5
br label %6
6: ; preds = %18, %2
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %21
9: ; preds = %6
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load i32, i32* %4
%13 = srem i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @err_die(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
br label %18
18: ; preds = %17
%19 = load i32, i32* %4
%20 = sdiv i32 %19, 2
store i32 %20, i32* %4
br label %6
21: ; preds = %6
%22 = load i32, i32* %3
%23 = load i32, i32* @SNDCTL_DSP_SETFRAGMENT
%24 = call i32 @ioctl(i32 %22, i32 %23, i32* %5)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @errno
%28 = call i32 @strerror(i32 %27)
%29 = call i32 (i8*, ...) @err_die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26, %21
ret void
}

LLVM IR (-O2):
@.str = [62 x i8] c"BUG: fragsz_arg to SNDCTL_DSP_SETFRAGMENT not a power of two\0A\00"
@SNDCTL_DSP_SETFRAGMENT = global i32 0
@.str.1 = [46 x i8] c"BUG: SNDCTL_DSP_SETFRAGMENT ioctl failed: %s\0A\00"
@errno = global i32 0
define void @set_au_blksz(i32 %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %17
6: ; preds = %2, %14
%7 = phi i32 [ %15, %14 ], [ %1, %2 ]
%8 = phi i32 [ %9, %14 ], [ 2147418112, %2 ]
%9 = add nuw nsw i32 %8, 1
%10 = and i32 %7, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %6
%13 = tail call i32 (i8*, ...) @err_die(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %6, %12
%15 = lshr i32 %7, 1
%16 = icmp ugt i32 %7, 3
br i1 %16, label %6, label %17
17: ; preds = %14, %2
%18 = phi i32 [ 2147418112, %2 ], [ %9, %14 ]
store i32 %18, i32* %3
%19 = load i32, i32* @SNDCTL_DSP_SETFRAGMENT
%20 = call i32 @ioctl(i32 %0, i32 %19, i32* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 (i8*, ...) @err_die(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %17
ret void
}