#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 */
struct bitstream_elmt_t {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ bitstream_bytealigned(struct bitstream_elmt_t *);
int bitstream_u(struct bitstream_elmt_t *, int);
int _rbsp_trailing_bits(struct bitstream_elmt_t *bs) {
  int bit;
  if ((bit = bitstream_u(bs, 1)) != 1) {
    return -1;
  }
  while (!bitstream_bytealigned(bs)) {
    if ((bit = bitstream_u(bs, 1)) != 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<_rbsp_trailing_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <bitstream_u@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x1,%eax
je     1152 <_rbsp_trailing_bits+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <_rbsp_trailing_bits+0x87>
jmp    1157 <_rbsp_trailing_bits+0x37>
mov    -0x10(%rbp),%rdi
call   1030 <bitstream_bytealigned@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1175 <_rbsp_trailing_bits+0x55>
jmp    11a0 <_rbsp_trailing_bits+0x80>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <bitstream_u@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     119b <_rbsp_trailing_bits+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <_rbsp_trailing_bits+0x87>
jmp    1157 <_rbsp_trailing_bits+0x37>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_rbsp_trailing_bits>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1,%esi
call   1040 <bitstream_u@plt>
mov    $0xffffffff,%ebp
cmp    $0x1,%eax
jne    1161 <_rbsp_trailing_bits+0x41>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <bitstream_bytealigned@plt>
test   %eax,%eax
jne    115f <_rbsp_trailing_bits+0x3f>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <bitstream_u@plt>
test   %eax,%eax
je     1140 <_rbsp_trailing_bits+0x20>
jmp    1161 <_rbsp_trailing_bits+0x41>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.bitstream_elmt_t = type { i32 }
define i32 @_rbsp_trailing_bits(%struct.bitstream_elmt_t* %0) {
%2 = alloca i32
%3 = alloca %struct.bitstream_elmt_t*
%4 = alloca i32
store %struct.bitstream_elmt_t* %0, %struct.bitstream_elmt_t** %3
%5 = load %struct.bitstream_elmt_t*, %struct.bitstream_elmt_t** %3
%6 = call i32 @bitstream_u(%struct.bitstream_elmt_t* %5, i32 1)
store i32 %6, i32* %4
%7 = icmp ne i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %22
9: ; preds = %1
br label %10
10: ; preds = %20, %9
%11 = load %struct.bitstream_elmt_t*, %struct.bitstream_elmt_t** %3
%12 = call i32 @bitstream_bytealigned(%struct.bitstream_elmt_t* %11)
%13 = icmp ne i32 %12, 0
%14 = xor i1 %13, true
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load %struct.bitstream_elmt_t*, %struct.bitstream_elmt_t** %3
%17 = call i32 @bitstream_u(%struct.bitstream_elmt_t* %16, i32 1)
store i32 %17, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 -1, i32* %2
br label %22
20: ; preds = %15
br label %10
21: ; preds = %10
store i32 0, i32* %2
br label %22
22: ; preds = %21, %19, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.bitstream_elmt_t = type { i32 }
define i32 @_rbsp_trailing_bits(%struct.bitstream_elmt_t* %0) {
%2 = tail call i32 @bitstream_u(%struct.bitstream_elmt_t* %0, i32 1)
%3 = icmp eq i32 %2, 1
br i1 %3, label %4, label %10
4: ; preds = %1, %7
%5 = tail call i32 @bitstream_bytealigned(%struct.bitstream_elmt_t* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = tail call i32 @bitstream_u(%struct.bitstream_elmt_t* %0, i32 1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %4, label %10
10: ; preds = %4, %7, %1
%11 = phi i32 [ -1, %1 ], [ 0, %4 ], [ -1, %7 ]
ret i32 %11
}