#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*/ err(int, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(unsigned int *);
int fwrite(unsigned int *, int, int, int /*<<< orphan*/ *);
unsigned int *get_serial(size_t *);
int /*<<< orphan*/ inc_uiarr(unsigned int *, size_t);
void inc_serial(void) {
  unsigned int *a;
  size_t len;
  FILE *fp;
  a = get_serial(&len);
  inc_uiarr(a, len);
  fp = fopen("serial", "w");
  if (fp == NULL)
    err(1, "fopen(SERIAL_FILE)");
  if (fwrite(a, sizeof(unsigned int), 1, fp) != 1)
    err(1, "fwrite()");
  fclose(fp);
  free(a);
}


x86 assembly (clang, -O0):
<inc_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
call   1050 <get_serial@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <inc_uiarr@plt>
lea    0xe67(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <inc_serial+0x55>
mov    $0x1,%edi
lea    0xe49(%rip),%rsi
call   1060 <err@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x4,%esi
mov    $0x1,%edx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     11f6 <inc_serial+0x86>
mov    $0x1,%edi
lea    0xe2b(%rip),%rsi
call   1060 <err@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inc_serial>:
push   %r14
push   %rbx
push   %rax
mov    %rsp,%rdi
call   1050 <get_serial@plt>
mov    %rax,%r14
mov    (%rsp),%rsi
mov    %rax,%rdi
call   1070 <inc_uiarr@plt>
lea    0xe6e(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11b7 <inc_serial+0x47>
lea    0xe5c(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
cmp    $0x1,%eax
je     11e2 <inc_serial+0x72>
lea    0xe44(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [7 x i8] c"serial\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"fopen(SERIAL_FILE)\00"
@.str.3 = [9 x i8] c"fwrite()\00"
define void @inc_serial() {
%1 = alloca i32*
%2 = alloca i64
%3 = alloca i32*
%4 = call i32* @get_serial(i64* %2)
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = load i64, i64* %2
%7 = call i32 @inc_uiarr(i32* %5, i64 %6)
%8 = 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* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = load i32*, i32** %1
%15 = load i32*, i32** %3
%16 = call i32 @fwrite(i32* %14, i32 4, i32 1, i32* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
%23 = load i32*, i32** %1
%24 = call i32 @free(i32* %23)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"serial\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [19 x i8] c"fopen(SERIAL_FILE)\00"
@.str.3 = [9 x i8] c"fwrite()\00"
define void @inc_serial() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i32* @get_serial(i64* %1)
%4 = load i64, i64* %1
%5 = call i32 @inc_uiarr(i32* %3, i64 %4)
%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))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i32 @fwrite(i32* %3, i32 4, i32 1, i32* %6)
%12 = icmp eq i32 %11, 1
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i32 @fclose(i32* %6)
%17 = call i32 @free(i32* %3)
ret void
}