#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 {
  unsigned long st_size;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int fstat(int, struct stat *);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
unsigned long mywc_b(const char *file_name) {
  int fd;
  struct stat stbuf;
  if ((fd = open(file_name, O_RDONLY)) == -1) {
    fprintf(stderr, "error: open %s\n%s\n", file_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  if (fstat(fd, &stbuf) == -1) {
    fprintf(stderr, "error: fstat %s\n%s\n", file_name, strerror(errno));
    exit(EXIT_FAILURE);
  }
  close(fd);
  return stbuf.st_size;
}


x86 assembly (clang, -O0):
<mywc_b>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    11d0 <mywc_b+0x70>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe43(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
jne    122b <mywc_b+0xcb>
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfb(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mywc_b>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     119c <mywc_b+0x3c>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
call   1080 <fstat@plt>
cmp    $0xffffffff,%eax
je     11bc <mywc_b+0x5c>
mov    %ebp,%edi
call   1030 <close@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e35(%rip),%rax
mov    (%rax),%ebp
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe46(%rip),%rsi
jmp    11da <mywc_b+0x7a>
mov    0x2e15(%rip),%rax
mov    (%rax),%ebp
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe39(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"error: open %s\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"error: fstat %s\0A%s\0A\00"
define i64 @mywc_b(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %2
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* %3
%19 = call i32 @fstat(i32 %18, %struct.stat* %4)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %2
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = load i32, i32* %3
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%33 = load i64, i64* %32
ret i64 %33
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"error: open %s\0A%s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [20 x i8] c"error: fstat %s\0A%s\0A\00"
define i64 @mywc_b(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
%15 = call i32 @fstat(i32 %5, %struct.stat* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %14
%25 = tail call i32 @close(i32 %5)
%26 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%27 = load i64, i64* %26
ret i64 %27
}