getlong(fd, l) long *l;
{
  char buf[4];
  if (read(fd, buf, 4) < 4)
    return -1;
  *l = ((((long)(buf[3] & 0377) << 8) | (long)(buf[2] & 0377) << 8) |
        (long)(buf[1] & 0377) << 8) |
       (long)(buf[0] & 0377);
  return 0;
}


x86 assembly (clang, -O0):
<getlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
cmp    $0x4,%eax
jge    1147 <getlong+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <getlong+0x87>
movsbl -0x11(%rbp),%eax
and    $0xff,%eax
movslq %eax,%rcx
shl    $0x8,%rcx
movsbl -0x12(%rbp),%eax
and    $0xff,%eax
cltq
shl    $0x8,%rax
or     %rax,%rcx
movsbl -0x13(%rbp),%eax
and    $0xff,%eax
cltq
shl    $0x8,%rax
or     %rax,%rcx
movsbl -0x14(%rbp),%eax
and    $0xff,%eax
cltq
or     %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlong>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x4,%ecx
jl     1159 <getlong+0x49>
mov    0xe(%rsp),%al
or     0xf(%rsp),%al
movzbl %al,%eax
movzbl 0xd(%rsp),%ecx
or     %rax,%rcx
shl    $0x8,%rcx
movzbl 0xc(%rsp),%eax
or     %rcx,%rax
mov    %rax,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @getlong(i32 %0, i64* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64*
%6 = alloca [4 x i8]
store i32 %0, i32* %4
store i64* %1, i64** %5
%7 = load i32, i32* %4
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%9 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %7, i8* %8, i32 4)
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %40
12: ; preds = %2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = and i32 %15, 255
%17 = sext i32 %16 to i64
%18 = shl i64 %17, 8
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = and i32 %21, 255
%23 = sext i32 %22 to i64
%24 = shl i64 %23, 8
%25 = or i64 %18, %24
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = and i32 %28, 255
%30 = sext i32 %29 to i64
%31 = shl i64 %30, 8
%32 = or i64 %25, %31
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = and i32 %35, 255
%37 = sext i32 %36 to i64
%38 = or i64 %32, %37
%39 = load i64*, i64** %5
store i64 %38, i64* %39
store i32 0, i32* %3
br label %40
40: ; preds = %12, %11
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @getlong(i32 %0, i64* 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 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %4, i32 4)
%6 = icmp slt i32 %5, 4
br i1 %6, label %21, label %7
7: ; preds = %2
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%9 = load i8, i8* %8
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%11 = load i8, i8* %10
%12 = or i8 %11, %9
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%14 = load i8, i8* %13
%15 = or i8 %12, %14
%16 = zext i8 %15 to i64
%17 = shl nuw nsw i64 %16, 8
%18 = load i8, i8* %4
%19 = zext i8 %18 to i64
%20 = or i64 %17, %19
store i64 %20, i64* %1
br label %21
21: ; preds = %2, %7
%22 = phi i32 [ 0, %7 ], [ -1, %2 ]
ret i32 %22
}