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

/* Variables and functions */
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(unsigned int *, int, int, int /*<<< orphan*/ *);
unsigned int *malloc(int);
int /*<<< orphan*/ memcpy(unsigned int *, unsigned int *, size_t);
unsigned int *get_serial(size_t *len) {
  FILE *fp;
  unsigned int num[1], *p;
  fp = fopen("serial", "r");
  if (fp == NULL)
    err(1, "fopen(%s)", "serial");
  *len = fread(num, sizeof(unsigned int), 1, fp);
  if (*len != 1)
    err(1, "fread(serial): %d", *len);
  fclose(fp);
  p = malloc(sizeof(num));
  memcpy(p, num, (*len) * sizeof(unsigned int));
  return p;
}


x86 assembly (clang, -O0):
<get_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <get_serial+0x48>
mov    $0x1,%edi
lea    0xe6f(%rip),%rsi
lea    0xe5f(%rip),%rdx
mov    $0x0,%al
call   1060 <err@plt>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x1,(%rax)
je     11f1 <get_serial+0x91>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
lea    0xe29(%rip),%rsi
mov    $0x0,%al
call   1060 <err@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x14(%rbp),%rsi
mov    -0x8(%rbp),%rax
mov    (%rax),%rdx
shl    $0x2,%rdx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_serial>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe92(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119c <get_serial+0x3c>
lea    0xe80(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <err@plt>
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,(%r14)
cmp    $0x1,%rax
je     11d2 <get_serial+0x72>
lea    0xe50(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <err@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    (%r14),%rdx
shl    $0x2,%rdx
lea    0x4(%rsp),%rsi
mov    %rax,%rdi
call   1050 <memcpy@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"serial\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"fopen(%s)\00"
@.str.3 = [18 x i8] c"fread(serial): %d\00"
define i32* @get_serial(i64* %0) {
%2 = alloca i64*
%3 = alloca i32*
%4 = alloca [1 x i32]
%5 = alloca i32*
store i64* %0, i64** %2
%6 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
%12 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%13 = load i32*, i32** %3
%14 = call i64 @fread(i32* %12, i32 4, i32 1, i32* %13)
%15 = load i64*, i64** %2
store i64 %14, i64* %15
%16 = load i64*, i64** %2
%17 = load i64, i64* %16
%18 = icmp ne i64 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %11
%20 = load i64*, i64** %2
%21 = load i64, i64* %20
%22 = call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %21)
br label %23
23: ; preds = %19, %11
%24 = load i32*, i32** %3
%25 = call i32 @fclose(i32* %24)
%26 = call i32* @malloc(i32 4)
store i32* %26, i32** %5
%27 = load i32*, i32** %5
%28 = getelementptr inbounds [1 x i32], [1 x i32]* %4, i64 0, i64 0
%29 = load i64*, i64** %2
%30 = load i64, i64* %29
%31 = mul i64 %30, 4
%32 = call i32 @memcpy(i32* %27, i32* %28, i64 %31)
%33 = load i32*, i32** %5
ret i32* %33
}

LLVM IR (-O2):
@.str = [7 x i8] c"serial\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [10 x i8] c"fopen(%s)\00"
@.str.3 = [18 x i8] c"fread(serial): %d\00"
define i32* @get_serial(i64* nocapture %0) {
%2 = alloca [1 x i32]
%3 = bitcast [1 x i32]* %2 to i8*
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
%10 = call i64 @fread(i32* %9, i32 4, i32 1, i32* %4)
store i64 %10, i64* %0
%11 = icmp eq i64 %10, 1
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 (i32, i8*, ...) @err(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i64 %10)
br label %14
14: ; preds = %12, %8
%15 = tail call i32 @fclose(i32* %4)
%16 = tail call i32* @malloc(i32 4)
%17 = load i64, i64* %0
%18 = shl i64 %17, 2
%19 = call i32 @memcpy(i32* %16, i32* %9, i64 %18)
ret i32* %16
}