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

/* Variables and functions */
int /*<<< orphan*/ fread(char *, size_t, size_t, int /*<<< orphan*/ *);
void src_int4_read(FILE *fd, int *val) {
  unsigned char b[4];
  fread((char *)&b[0], (size_t)1, (size_t)4, fd);
  *val = 0;
  *val = (int)((int)((int)(b[0] << 8) + ((int)b[1] << 8)) + ((int)b[2] << 8)) +
         (int)b[3];
}


x86 assembly (clang, -O0):
<src_int4_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movzbl -0x14(%rbp),%ecx
shl    $0x8,%ecx
movzbl -0x13(%rbp),%eax
shl    $0x8,%eax
add    %eax,%ecx
movzbl -0x12(%rbp),%eax
shl    $0x8,%eax
add    %eax,%ecx
movzbl -0x11(%rbp),%eax
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<src_int4_read>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rcx
lea    0xc(%rsp),%rdi
mov    $0x1,%esi
mov    $0x4,%edx
call   1030 <fread@plt>
movzbl 0xc(%rsp),%eax
movzbl 0xd(%rsp),%ecx
add    %eax,%ecx
movzbl 0xe(%rsp),%eax
add    %ecx,%eax
shl    $0x8,%eax
movzbl 0xf(%rsp),%ecx
or     %eax,%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @src_int4_read(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [4 x i8]
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32 @fread(i8* %6, i64 1, i64 4, i32* %7)
%9 = load i32*, i32** %4
store i32 0, i32* %9
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = shl i32 %12, 8
%14 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl i32 %16, 8
%18 = add nsw i32 %13, %17
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl i32 %21, 8
%23 = add nsw i32 %18, %22
%24 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = add nsw i32 %23, %26
%28 = load i32*, i32** %4
store i32 %27, i32* %28
ret void
}

LLVM IR (-O2):
define void @src_int4_read(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = alloca [4 x i8]
%4 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%5 = call i32 @fread(i8* %4, i64 1, i64 4, i32* %0)
%6 = load i8, i8* %4
%7 = zext i8 %6 to i32
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = add nuw nsw i32 %10, %7
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = add nuw nsw i32 %11, %14
%16 = shl nuw nsw i32 %15, 8
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = or i32 %16, %19
store i32 %20, i32* %1
ret void
}