#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 char uint32_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, int);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int decode_guint32(FILE *in, uint32_t *i) {
  char buf[sizeof(uint32_t)];
  size_t r = fread(buf, 1, sizeof(buf), in);
  if (r != sizeof(buf)) {
    do {
      fprintf(stderr,
              "could not read all of guint32, got %zu bytes of %zu bytes.", r,
              sizeof(buf));
      putc('\n', stderr);
    } while (0);
    return -1;
  }
  *i = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];
  return 0;
}


x86 assembly (clang, -O0):
<decode_guint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x19(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x1,-0x28(%rbp)
je     11a5 <decode_guint32+0x75>
jmp    1168 <decode_guint32+0x38>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe84(%rip),%rsi
mov    $0x1,%ecx
call   1050 <fprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d3 <decode_guint32+0xa3>
movsbl -0x19(%rbp),%eax
shl    $0x18,%eax
movsbl -0x18(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movsbl -0x17(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movsbl -0x16(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_guint32>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rcx
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%rax
jne    115f <decode_guint32+0x2f>
mov    0x12(%rsp),%al
mov    %al,(%rbx)
xor    %eax,%eax
jmp    118d <decode_guint32+0x5d>
mov    0x2e7a(%rip),%rbx
mov    (%rbx),%edi
lea    0xe91(%rip),%rsi
mov    %rax,%rdx
mov    $0x1,%ecx
call   1050 <fprintf@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1040 <putc@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [59 x i8] c"could not read all of guint32, got %zu bytes of %zu bytes.\00"
define i32 @decode_guint32(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca [1 x i8]
%7 = alloca i64
store i32* %0, i32** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%9 = load i32*, i32** %4
%10 = call i64 @fread(i8* %8, i32 1, i32 1, i32* %9)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp ne i64 %11, 1
br i1 %12, label %13, label %21
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i32, i32* @stderr
%16 = load i64, i64* %7
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i64 %16, i32 1)
%18 = load i32, i32* @stderr
%19 = call i32 @putc(i8 signext 10, i32 %18)
br label %20
20: ; preds = %14
store i32 -1, i32* %3
br label %42
21: ; preds = %2
%22 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = shl i32 %24, 24
%26 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 1
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = shl i32 %28, 16
%30 = or i32 %25, %29
%31 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 2
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = shl i32 %33, 8
%35 = or i32 %30, %34
%36 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 3
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = or i32 %35, %38
%40 = trunc i32 %39 to i8
%41 = load i8*, i8** %5
store i8 %40, i8* %41
store i32 0, i32* %3
br label %42
42: ; preds = %21, %20
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [59 x i8] c"could not read all of guint32, got %zu bytes of %zu bytes.\00"
define i32 @decode_guint32(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = call i64 @fread(i8* %4, i32 1, i32 1, i32* %0)
%6 = icmp eq i64 %5, 1
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i64 %5, i32 1)
%10 = load i32, i32* @stderr
%11 = tail call i32 @putc(i8 signext 10, i32 %10)
br label %15
12: ; preds = %2
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 3
%14 = load i8, i8* %13
store i8 %14, i8* %1
br label %15
15: ; preds = %12, %7
%16 = phi i32 [ -1, %7 ], [ 0, %12 ]
ret i32 %16
}