#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 uint32_t;
typedef int r;
typedef int g;
typedef int b;
typedef int a;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int getc(int /*<<< orphan*/ *);
uint32_t read_pixel(FILE *fp, int rdalpha) {
  int r, g, b, a;
  b = getc(fp);
  g = getc(fp);
  r = getc(fp);
  a = rdalpha ? getc(fp) : 0xff;
  return ((((a)&0xff) << 24) | (((r)&0xff) << 0) | (((g)&0xff) << 8) |
          (((b)&0xff) << 16));
}


x86 assembly (clang, -O0):
<read_pixel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     115e <read_pixel+0x4e>
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,-0x20(%rbp)
jmp    116b <read_pixel+0x5b>
mov    $0xff,%eax
mov    %eax,-0x20(%rbp)
jmp    116b <read_pixel+0x5b>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0xff,%eax
shl    $0x18,%eax
mov    -0x10(%rbp),%ecx
and    $0xff,%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    -0x14(%rbp),%ecx
and    $0xff,%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x18(%rbp),%ecx
and    $0xff,%ecx
shl    $0x10,%ecx
or     %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pixel>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <getc@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <getc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <getc@plt>
mov    %eax,%r15d
test   %r12d,%r12d
je     114d <read_pixel+0x3d>
mov    %rbx,%rdi
call   1030 <getc@plt>
shl    $0x18,%eax
jmp    1152 <read_pixel+0x42>
mov    $0xff000000,%eax
movzbl %r15b,%edx
shl    $0x8,%ebp
movzwl %bp,%esi
movzbl %r14b,%ecx
shl    $0x10,%ecx
or     %edx,%ecx
or     %esi,%ecx
or     %eax,%ecx
mov    %ecx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_pixel(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = load i32*, i32** %3
%10 = call i32 @getc(i32* %9)
store i32 %10, i32* %7
%11 = load i32*, i32** %3
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %6
%13 = load i32*, i32** %3
%14 = call i32 @getc(i32* %13)
store i32 %14, i32* %5
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i32*, i32** %3
%19 = call i32 @getc(i32* %18)
br label %21
20: ; preds = %2
br label %21
21: ; preds = %20, %17
%22 = phi i32 [ %19, %17 ], [ 255, %20 ]
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = and i32 %23, 255
%25 = shl i32 %24, 24
%26 = load i32, i32* %5
%27 = and i32 %26, 255
%28 = shl i32 %27, 0
%29 = or i32 %25, %28
%30 = load i32, i32* %6
%31 = and i32 %30, 255
%32 = shl i32 %31, 8
%33 = or i32 %29, %32
%34 = load i32, i32* %7
%35 = and i32 %34, 255
%36 = shl i32 %35, 16
%37 = or i32 %33, %36
ret i32 %37
}

LLVM IR (-O2):
define i32 @read_pixel(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = tail call i32 @getc(i32* %0)
%5 = tail call i32 @getc(i32* %0)
%6 = icmp eq i32 %1, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @getc(i32* %0)
%9 = shl i32 %8, 24
br label %10
10: ; preds = %2, %7
%11 = phi i32 [ %9, %7 ], [ -16777216, %2 ]
%12 = and i32 %5, 255
%13 = shl i32 %4, 8
%14 = and i32 %13, 65280
%15 = shl i32 %3, 16
%16 = and i32 %15, 16711680
%17 = or i32 %12, %16
%18 = or i32 %17, %14
%19 = or i32 %18, %11
ret i32 %19
}