#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 mode_t;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ atoi(char *);
char *basename(char *);
int /*<<< orphan*/ close(int);
int errno;
unsigned int htonl(int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int write(int, unsigned int *, int);
int main(int argc, char **argv) {
  unsigned int zero = 0;
  int fd;
  unsigned int size;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  if (argc != 3) {
    printf("Usage: %s [integer size] [output file]\n", basename(argv[0]));
    printf("Example: %s 12288475 initrd.size\n", basename(argv[0]));
    return 0;
  }
  size = htonl(atoi(argv[1]));
  fd = open(argv[2], O_CREAT | O_RDWR, mode);
  if (write(fd, &zero, sizeof(int)) == -1) {
    perror("writing initrd.size (zero)");
    return errno;
  }
  if (write(fd, &size, sizeof(int)) == -1) {
    perror("writing initrd.size (size)");
    return errno;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    0x2e2b(%rip),%rcx
or     (%rcx),%eax
mov    0x2e0a(%rip),%rcx
or     (%rcx),%eax
mov    0x2df9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1210 <main+0x90>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <basename@plt>
mov    %rax,%rsi
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <basename@plt>
mov    %rax,%rsi
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12c9 <main+0x149>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    -0x20(%rbp),%edx
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1283 <main+0x103>
lea    0xddd(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c9 <main+0x149>
mov    -0x18(%rbp),%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    12ba <main+0x13a>
lea    0xdc1(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12c9 <main+0x149>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
movl   $0x0,0x4(%rsp)
cmp    $0x3,%edi
jne    1220 <main+0xa0>
mov    0x2e12(%rip),%rax
mov    0x2e33(%rip),%rcx
mov    (%rcx),%ebp
or     (%rax),%ebp
mov    0x2e10(%rip),%rax
or     (%rax),%ebp
mov    0x2dff(%rip),%rax
or     (%rax),%ebp
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,(%rsp)
mov    0x10(%rbx),%rdi
mov    0x2e1f(%rip),%rax
mov    0x2e00(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebp,%edx
call   1080 <open@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1257 <main+0xd7>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     1260 <main+0xe0>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    124e <main+0xce>
mov    (%rbx),%rdi
call   1070 <basename@plt>
lea    0xdd1(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1070 <basename@plt>
lea    0xde2(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdec(%rip),%rdi
jmp    1267 <main+0xe7>
lea    0xdfe(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
jmp    1250 <main+0xd0>

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [40 x i8] c"Usage: %s [integer size] [output file]\0A\00"
@.str.1 = [34 x i8] c"Example: %s 12288475 initrd.size\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [27 x i8] c"writing initrd.size (zero)\00"
@errno = global i32 0
@.str.3 = [27 x i8] c"writing initrd.size (size)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* @S_IRUSR
%11 = load i32, i32* @S_IWUSR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRGRP
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IROTH
%16 = or i32 %14, %15
store i32 %16, i32* %9
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %30
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i8* @basename(i8* %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i8* @basename(i8* %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %28)
store i32 0, i32* %3
br label %60
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = call i32 @htonl(i32 %34)
store i32 %35, i32* %8
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = load i32, i32* @O_CREAT
%40 = load i32, i32* @O_RDWR
%41 = or i32 %39, %40
%42 = load i32, i32* %9
%43 = call i32 @open(i8* %38, i32 %41, i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = call i32 @write(i32 %44, i32* %6, i32 4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %30
%48 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* @errno
store i32 %49, i32* %3
br label %60
50: ; preds = %30
%51 = load i32, i32* %7
%52 = call i32 @write(i32 %51, i32* %8, i32 4)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* @errno
store i32 %56, i32* %3
br label %60
57: ; preds = %50
%58 = load i32, i32* %7
%59 = call i32 @close(i32 %58)
store i32 0, i32* %3
br label %60
60: ; preds = %57, %54, %47, %19
%61 = load i32, i32* %3
ret i32 %61
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [40 x i8] c"Usage: %s [integer size] [output file]\0A\00"
@.str.1 = [34 x i8] c"Example: %s 12288475 initrd.size\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.2 = [27 x i8] c"writing initrd.size (zero)\00"
@errno = global i32 0
@.str.3 = [27 x i8] c"writing initrd.size (size)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = tail call i8* @basename(i8* %9)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %1
%13 = tail call i8* @basename(i8* %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %46
15: ; preds = %2
%16 = load i32, i32* @S_IRUSR
%17 = load i32, i32* @S_IWUSR
%18 = or i32 %17, %16
%19 = load i32, i32* @S_IRGRP
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IROTH
%22 = or i32 %20, %21
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i32 @htonl(i32 %25)
store i32 %26, i32* %4
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_CREAT
%30 = load i32, i32* @O_RDWR
%31 = or i32 %30, %29
%32 = tail call i32 @open(i8* %28, i32 %31, i32 %22)
%33 = call i32 @write(i32 %32, i32* %3, i32 4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %15
%36 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @errno
br label %46
38: ; preds = %15
%39 = call i32 @write(i32 %32, i32* %4, i32 4)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = tail call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @errno
br label %46
44: ; preds = %38
%45 = tail call i32 @close(i32 %32)
br label %46
46: ; preds = %44, %41, %35, %8
%47 = phi i32 [ 0, %8 ], [ %37, %35 ], [ %43, %41 ], [ 0, %44 ]
ret i32 %47
}