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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("host [file ...]\n");
    exit(1);
  }
  int fd, i;
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    printf("Failed to open file\n");
    exit(errno);
  }
  struct stat fstatInfo;
  if (fstat(fd, &fstatInfo) == -1) {
    printf("Configuration could not be read\n");
    close(fd);
    exit(errno);
  }
  char buf;
  printf("%lld\n0x", fstatInfo.st_size);
  for (i = 0; i < 8; i++) {
    if (read(fd, &buf, 1) == -1) {
      printf("Error reading file\n");
      close(fd);
      exit(errno);
    }
    printf("%X", buf);
  }
  printf("\n");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11d6 <main+0x76>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    120f <main+0xaf>
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%esi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x8,-0x18(%rbp)
jge    128f <main+0x12f>
mov    -0x14(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
jne    126f <main+0x10f>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movsbl -0x21(%rbp),%esi
lea    0xde9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1227 <main+0xc7>
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1368 <main+0x1e8>
mov    0x8(%rsi),%rdi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     137e <main+0x1fe>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   10a0 <fstat@plt>
cmp    $0xffffffff,%eax
je     138c <main+0x20c>
mov    0x8(%rsp),%esi
lea    0xe35(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xe10(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xde3(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xdb6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xd89(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xd5c(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xd0a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1070 <read@plt>
cmp    $0xffffffff,%eax
je     1347 <main+0x1c7>
movsbl 0x7(%rsp),%esi
lea    0xce1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xcbd(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
lea    0xce3(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xcb9(%rip),%rdi
call   1040 <puts@plt>
jmp    135a <main+0x1da>
lea    0xc8b(%rip),%rdi
jmp    134e <main+0x1ce>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"host [file ...]\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [21 x i8] c"Failed to open file\0A\00"
@errno = global i32 0
@.str.2 = [33 x i8] c"Configuration could not be read\0A\00"
@.str.3 = [8 x i8] c"%lld\0A0x\00"
@.str.4 = [20 x i8] c"Error reading file\0A\00"
@.str.5 = [3 x i8] c"%X\00"
@.str.6 = [2 x i8] c"\0A\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 %struct.stat
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i8* %18, i32 %19)
store i32 %20, i32* %6
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @errno
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = load i32, i32* %6
%28 = call i32 @fstat(i32 %27, %struct.stat* %8)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = call i32 @close(i32 %32)
%34 = load i32, i32* @errno
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %26
%37 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %38)
store i32 0, i32* %7
br label %40
40: ; preds = %57, %36
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 8
br i1 %42, label %43, label %60
43: ; preds = %40
%44 = load i32, i32* %6
%45 = call i32 @read(i32 %44, i8* %9, i32 1)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %53
47: ; preds = %43
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
%51 = load i32, i32* @errno
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %43
%54 = load i8, i8* %9
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %40
60: ; preds = %40
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@errno = global i32 0
@.str.3 = [8 x i8] c"%lld\0A0x\00"
@.str.5 = [3 x i8] c"%X\00"
@str = [19 x i8] c"Error reading file\00"
@str.7 = [32 x i8] c"Configuration could not be read\00"
@str.8 = [20 x i8] c"Failed to open file\00"
@str.9 = [16 x i8] c"host [file ...]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = alloca i8
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.9, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.8, i64 0, i64 0))
%17 = load i32, i32* @errno
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %9
%20 = bitcast %struct.stat* %3 to i8*
%21 = call i32 @fstat(i32 %13, %struct.stat* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %19
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%25 = tail call i32 @close(i32 %13)
%26 = load i32, i32* @errno
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
%29 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%30 = load i32, i32* %29
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %30)
%32 = call i32 @read(i32 %13, i8* %4, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %39
34: ; preds = %75, %69, %63, %57, %51, %45, %39, %28
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%36 = tail call i32 @close(i32 %13)
%37 = load i32, i32* @errno
%38 = tail call i32 @exit(i32 %37)
unreachable
39: ; preds = %28
%40 = load i8, i8* %4
%41 = sext i8 %40 to i32
%42 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %41)
%43 = call i32 @read(i32 %13, i8* %4, i32 1)
%44 = icmp eq i32 %43, -1
br i1 %44, label %34, label %45
45: ; preds = %39
%46 = load i8, i8* %4
%47 = sext i8 %46 to i32
%48 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = call i32 @read(i32 %13, i8* %4, i32 1)
%50 = icmp eq i32 %49, -1
br i1 %50, label %34, label %51
51: ; preds = %45
%52 = load i8, i8* %4
%53 = sext i8 %52 to i32
%54 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %53)
%55 = call i32 @read(i32 %13, i8* %4, i32 1)
%56 = icmp eq i32 %55, -1
br i1 %56, label %34, label %57
57: ; preds = %51
%58 = load i8, i8* %4
%59 = sext i8 %58 to i32
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = call i32 @read(i32 %13, i8* %4, i32 1)
%62 = icmp eq i32 %61, -1
br i1 %62, label %34, label %63
63: ; preds = %57
%64 = load i8, i8* %4
%65 = sext i8 %64 to i32
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %65)
%67 = call i32 @read(i32 %13, i8* %4, i32 1)
%68 = icmp eq i32 %67, -1
br i1 %68, label %34, label %69
69: ; preds = %63
%70 = load i8, i8* %4
%71 = sext i8 %70 to i32
%72 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = call i32 @read(i32 %13, i8* %4, i32 1)
%74 = icmp eq i32 %73, -1
br i1 %74, label %34, label %75
75: ; preds = %69
%76 = load i8, i8* %4
%77 = sext i8 %76 to i32
%78 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %77)
%79 = call i32 @read(i32 %13, i8* %4, i32 1)
%80 = icmp eq i32 %79, -1
br i1 %80, label %34, label %81
81: ; preds = %75
%82 = load i8, i8* %4
%83 = sext i8 %82 to i32
%84 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %83)
%85 = tail call i32 @putchar(i32 10)
%86 = tail call i32 @close(i32 %13)
ret i32 0
}