#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 */
struct stat {
  int /*<<< orphan*/ st_size;
};
typedef int mode_t;

/* Variables and functions */
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
char *basename(char *);
int /*<<< orphan*/ close(int);
unsigned int htonl(int /*<<< orphan*/);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int write(int, unsigned int *, int);
int main(int argc, char **argv) {
  char *cmd = basename(argv[0]);
  char *address = NULL, *input = NULL, *output = NULL;
  struct stat initrd_stat;
  unsigned int addr = 0, size = 0, zero = 0;
  int fd, rc;
  mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
  if (argc != 4) {
    printf("Generate initrd address and size file used by the .ins LPAR load "
           "mechanism\n");
    printf("Usage: %s [address] [initrd] [output file]\n", cmd);
    printf("Example: %s 0x02000000 initrd.img initrd.addrsize\n", cmd);
    return 1;
  }
  address = argv[1];
  input = argv[2];
  output = argv[3];
  rc = stat(input, &initrd_stat);
  if (rc) {
    perror("Error getting initrd stats ");
    return 2;
  }
  addr = htonl(strtoul(address, NULL, 0));
  size = htonl(initrd_stat.st_size);
  fd = open(output, O_CREAT | O_RDWR, mode);
  if (write(fd, &zero, sizeof(int)) == -1) {
    perror("writing initrd.addr (zero) ");
    return 3;
  }
  if (write(fd, &addr, sizeof(int)) == -1) {
    perror("writing initrd.addr (addr) ");
    return 4;
  }
  if (write(fd, &zero, sizeof(int)) == -1) {
    perror("writing initrd.addr (zero) ");
    return 5;
  }
  if (write(fd, &size, sizeof(int)) == -1) {
    perror("writing initrd.addr (size) ");
    return 6;
  }
  close(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <basename@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    0x2de5(%rip),%rcx
or     (%rcx),%eax
mov    0x2dcc(%rip),%rcx
or     (%rcx),%eax
mov    0x2dbb(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1252 <main+0xc2>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     12a8 <main+0x118>
lea    0xe14(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,%edi
call   1050 <htonl@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
mov    0x2d00(%rip),%rax
or     (%rax),%esi
mov    -0x50(%rbp),%edx
call   1090 <open@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    131f <main+0x18f>
lea    0xdb9(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x3,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x48(%rbp),%edi
lea    -0x3c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1351 <main+0x1c1>
lea    0xda3(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x4,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x48(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    1383 <main+0x1f3>
lea    0xd55(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x5,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x48(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    13b5 <main+0x225>
lea    0xd5b(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x6,-0x4(%rbp)
jmp    13c9 <main+0x239>
mov    -0x48(%rbp),%edi
call   1060 <close@plt>
mov    0x2bec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    (%rsi),%rdi
call   1080 <basename@plt>
movl   $0x0,0x4(%rsp)
cmp    $0x4,%ebx
jne    12cb <main+0x12b>
mov    0x2de9(%rip),%rax
mov    0x2e02(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    0x2de7(%rip),%rax
or     (%rax),%ebx
mov    0x2dd6(%rip),%rax
or     (%rax),%ebx
mov    0x8(%rbp),%r15
mov    0x10(%rbp),%rdi
mov    0x18(%rbp),%r14
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
test   %eax,%eax
jne    130e <main+0x16e>
mov    %r15,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %eax,%edi
call   1060 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    0x8(%rsp),%edi
call   1060 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    0x2dc3(%rip),%rax
mov    0x2da4(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r14,%rdi
mov    %ebx,%edx
call   10a0 <open@plt>
mov    %eax,%ebx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1321 <main+0x181>
lea    0x14(%rsp),%rsi
mov    $0x4,%ebp
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1334 <main+0x194>
lea    0x4(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1342 <main+0x1a2>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1355 <main+0x1b5>
mov    %ebx,%edi
call   1070 <close@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%ebp
jmp    1301 <main+0x161>
mov    %rax,%r14
lea    0xdfa(%rip),%rdi
call   1030 <puts@plt>
lea    0xd1f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xd3a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%ebp
jmp    1301 <main+0x161>
lea    0xd53(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x3,%ebp
jmp    1301 <main+0x161>
lea    0xd5c(%rip),%rdi
call   10b0 <perror@plt>
jmp    1301 <main+0x161>
lea    0xd32(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x5,%ebp
jmp    1301 <main+0x161>
lea    0xd57(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x6,%ebp
jmp    1301 <main+0x161>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str = [76 x i8] c"Generate initrd address and size file used by the .ins LPAR load mechanism\0A\00"
@.str.1 = [44 x i8] c"Usage: %s [address] [initrd] [output file]\0A\00"
@.str.2 = [51 x i8] c"Example: %s 0x02000000 initrd.img initrd.addrsize\0A\00"
@.str.3 = [28 x i8] c"Error getting initrd stats \00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.4 = [28 x i8] c"writing initrd.addr (zero) \00"
@.str.5 = [28 x i8] c"writing initrd.addr (addr) \00"
@.str.6 = [28 x i8] c"writing initrd.addr (size) \00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca %struct.stat
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i8* @basename(i8* %19)
store i8* %20, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%21 = load i32, i32* @S_IRUSR
%22 = load i32, i32* @S_IWUSR
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRGRP
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IROTH
%27 = or i32 %25, %26
store i32 %27, i32* %16
%28 = load i32, i32* %4
%29 = icmp ne i32 %28, 4
br i1 %29, label %30, label %36
30: ; preds = %2
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
%32 = load i8*, i8** %6
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %32)
%34 = load i8*, i8** %6
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %92
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
store i8* %39, i8** %7
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
store i8* %42, i8** %8
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
store i8* %45, i8** %9
%46 = load i8*, i8** %8
%47 = call i32 @stat(i8* %46, %struct.stat* %10)
store i32 %47, i32* %15
%48 = load i32, i32* %15
%49 = icmp ne i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %36
%51 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
store i32 2, i32* %3
br label %92
52: ; preds = %36
%53 = load i8*, i8** %7
%54 = call i32 @strtoul(i8* %53, i32* null, i32 0)
%55 = call i32 @htonl(i32 %54)
store i32 %55, i32* %11
%56 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @htonl(i32 %57)
store i32 %58, i32* %12
%59 = load i8*, i8** %9
%60 = load i32, i32* @O_CREAT
%61 = load i32, i32* @O_RDWR
%62 = or i32 %60, %61
%63 = load i32, i32* %16
%64 = call i32 @open(i8* %59, i32 %62, i32 %63)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = call i32 @write(i32 %65, i32* %13, i32 4)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %70
68: ; preds = %52
%69 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %92
70: ; preds = %52
%71 = load i32, i32* %14
%72 = call i32 @write(i32 %71, i32* %11, i32 4)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %70
%75 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
store i32 4, i32* %3
br label %92
76: ; preds = %70
%77 = load i32, i32* %14
%78 = call i32 @write(i32 %77, i32* %13, i32 4)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
store i32 5, i32* %3
br label %92
82: ; preds = %76
%83 = load i32, i32* %14
%84 = call i32 @write(i32 %83, i32* %12, i32 4)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %88
86: ; preds = %82
%87 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
store i32 6, i32* %3
br label %92
88: ; preds = %82
%89 = load i32, i32* %14
%90 = call i32 @close(i32 %89)
%91 = load i32, i32* @EXIT_SUCCESS
store i32 %91, i32* %3
br label %92
92: ; preds = %88, %86, %80, %74, %68, %50, %30
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [44 x i8] c"Usage: %s [address] [initrd] [output file]\0A\00"
@.str.2 = [51 x i8] c"Example: %s 0x02000000 initrd.img initrd.addrsize\0A\00"
@.str.3 = [28 x i8] c"Error getting initrd stats \00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.4 = [28 x i8] c"writing initrd.addr (zero) \00"
@.str.5 = [28 x i8] c"writing initrd.addr (addr) \00"
@.str.6 = [28 x i8] c"writing initrd.addr (size) \00"
@EXIT_SUCCESS = global i32 0
@str = [75 x i8] c"Generate initrd address and size file used by the .ins LPAR load mechanism\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = load i8*, i8** %1
%8 = tail call i8* @basename(i8* %7)
%9 = bitcast %struct.stat* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = load i32, i32* @S_IRUSR
%14 = load i32, i32* @S_IWUSR
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IRGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IROTH
%19 = or i32 %17, %18
%20 = icmp eq i32 %0, 4
br i1 %20, label %25, label %21
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %68
25: ; preds = %2
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = getelementptr inbounds i8*, i8** %1, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @stat(i8* %29, %struct.stat* %3)
%33 = icmp eq i32 %32, 0
br i1 %33, label %36, label %34
34: ; preds = %25
%35 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
br label %68
36: ; preds = %25
%37 = tail call i32 @strtoul(i8* nocapture %27, i32* null, i32 0)
%38 = tail call i32 @htonl(i32 %37)
store i32 %38, i32* %4
%39 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%40 = load i32, i32* %39
%41 = tail call i32 @htonl(i32 %40)
store i32 %41, i32* %5
%42 = load i32, i32* @O_CREAT
%43 = load i32, i32* @O_RDWR
%44 = or i32 %43, %42
%45 = tail call i32 @open(i8* %31, i32 %44, i32 %19)
%46 = call i32 @write(i32 %45, i32* %6, i32 4)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %50
48: ; preds = %36
%49 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %68
50: ; preds = %36
%51 = call i32 @write(i32 %45, i32* %4, i32 4)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %68
55: ; preds = %50
%56 = call i32 @write(i32 %45, i32* %6, i32 4)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
br label %68
60: ; preds = %55
%61 = call i32 @write(i32 %45, i32* %5, i32 4)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
br label %68
65: ; preds = %60
%66 = tail call i32 @close(i32 %45)
%67 = load i32, i32* @EXIT_SUCCESS
br label %68
68: ; preds = %65, %63, %58, %53, %48, %34, %21
%69 = phi i32 [ 1, %21 ], [ 2, %34 ], [ 3, %48 ], [ 4, %53 ], [ 5, %58 ], [ 6, %63 ], [ %67, %65 ]
ret i32 %69
}