#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 */
unsigned int foo(void *);
void bar(void *x, void *y, int z) {
  unsigned c;
  while (z--) {
    c = foo(y);
    *(unsigned *)x = (c & 0xf80000) >> 9 | (c & 0xf800) >> 6 | (c & 0xf8) >> 3 |
                     (c & 0x80000000) >> 16;
  }
}


x86 assembly (clang, -O0):
<bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1181 <bar+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <foo@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
and    $0xf80000,%ecx
shr    $0x9,%ecx
mov    -0x18(%rbp),%eax
and    $0xf800,%eax
shr    $0x6,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%eax
and    $0xf8,%eax
shr    $0x3,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%eax
and    $0x80000000,%eax
shr    $0x10,%eax
or     %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1123 <bar+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bar>:
push   %r15
push   %r14
push   %rbx
test   %edx,%edx
je     116c <bar+0x5c>
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1030 <foo@plt>
mov    %eax,%ecx
shr    $0x9,%ecx
and    $0x7c00,%ecx
mov    %eax,%edx
shr    $0x6,%edx
and    $0x3e0,%edx
or     %ecx,%edx
mov    %eax,%ecx
shr    $0x3,%ecx
and    $0x1f,%ecx
or     %edx,%ecx
shr    $0x10,%eax
and    $0x8000,%eax
or     %ecx,%eax
mov    %eax,(%r15)
add    $0xffffffff,%ebx
jne    1130 <bar+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @bar(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %12, %3
%9 = load i32, i32* %6
%10 = add nsw i32 %9, -1
store i32 %10, i32* %6
%11 = icmp ne i32 %9, 0
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = call i32 @foo(i8* %13)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = and i32 %15, 16252928
%17 = lshr i32 %16, 9
%18 = load i32, i32* %7
%19 = and i32 %18, 63488
%20 = lshr i32 %19, 6
%21 = or i32 %17, %20
%22 = load i32, i32* %7
%23 = and i32 %22, 248
%24 = lshr i32 %23, 3
%25 = or i32 %21, %24
%26 = load i32, i32* %7
%27 = and i32 %26, -2147483648
%28 = lshr i32 %27, 16
%29 = or i32 %25, %28
%30 = load i8*, i8** %4
%31 = bitcast i8* %30 to i32*
store i32 %29, i32* %31
br label %8
32: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @bar(i8* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %23, label %5
5: ; preds = %3
%6 = bitcast i8* %0 to i32*
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ %2, %5 ], [ %9, %7 ]
%9 = add nsw i32 %8, -1
%10 = tail call i32 @foo(i8* %1)
%11 = lshr i32 %10, 9
%12 = and i32 %11, 31744
%13 = lshr i32 %10, 6
%14 = and i32 %13, 992
%15 = or i32 %12, %14
%16 = lshr i32 %10, 3
%17 = and i32 %16, 31
%18 = or i32 %15, %17
%19 = lshr i32 %10, 16
%20 = and i32 %19, 32768
%21 = or i32 %18, %20
store i32 %21, i32* %6
%22 = icmp eq i32 %9, 0
br i1 %22, label %23, label %7
23: ; preds = %7, %3
ret void
}