#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 state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read_meminfo(struct state *);
int read_stat(struct state *);
int read_vmstat(struct state *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void read_state(struct state *s) {
  int error;
  error = read_meminfo(s);
  if (error) {
    fprintf(stderr, "vmstat: could not read /proc/meminfo: %s\n",
            strerror(error));
    exit(EXIT_FAILURE);
  }
  error = read_stat(s);
  if (error) {
    fprintf(stderr, "vmstat: could not read /proc/stat: %s\n", strerror(error));
    exit(EXIT_FAILURE);
  }
  error = read_vmstat(s);
  if (error) {
    fprintf(stderr, "vmstat: could not read /proc/vmstat: %s\n",
            strerror(error));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<read_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <read_meminfo@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11b6 <read_state+0x56>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <read_stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1200 <read_state+0xa0>
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe3d(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <read_vmstat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     124a <read_state+0xea>
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_state>:
push   %rbx
mov    %rdi,%rbx
call   1030 <read_meminfo@plt>
test   %eax,%eax
jne    1187 <read_state+0x27>
mov    %rbx,%rdi
call   1050 <read_stat@plt>
test   %eax,%eax
jne    11a0 <read_state+0x40>
mov    %rbx,%rdi
call   1060 <read_vmstat@plt>
test   %eax,%eax
jne    11b9 <read_state+0x59>
pop    %rbx
ret
mov    0x2e52(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <strerror@plt>
lea    0xe62(%rip),%rsi
jmp    11d0 <read_state+0x70>
mov    0x2e39(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <strerror@plt>
lea    0xe73(%rip),%rsi
jmp    11d0 <read_state+0x70>
mov    0x2e20(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1080 <strerror@plt>
lea    0xe81(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.state = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"vmstat: could not read /proc/meminfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"vmstat: could not read /proc/stat: %s\0A\00"
@.str.2 = [41 x i8] c"vmstat: could not read /proc/vmstat: %s\0A\00"
define void @read_state(%struct.state* %0) {
%2 = alloca %struct.state*
%3 = alloca i32
store %struct.state* %0, %struct.state** %2
%4 = load %struct.state*, %struct.state** %2
%5 = call i32 @read_meminfo(%struct.state* %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* %3
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load %struct.state*, %struct.state** %2
%17 = call i32 @read_stat(%struct.state* %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = load i32, i32* %3
%23 = call i8* @strerror(i32 %22)
%24 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %15
%28 = load %struct.state*, %struct.state** %2
%29 = call i32 @read_vmstat(%struct.state* %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* %3
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %27
ret void
}

LLVM IR (-O2):
%struct.state = type { i32 }
@stderr = global i32 0
@.str = [42 x i8] c"vmstat: could not read /proc/meminfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"vmstat: could not read /proc/stat: %s\0A\00"
@.str.2 = [41 x i8] c"vmstat: could not read /proc/vmstat: %s\0A\00"
define void @read_state(%struct.state* %0) {
%2 = tail call i32 @read_meminfo(%struct.state* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i8* @strerror(i32 %2)
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i32 @read_stat(%struct.state* %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i8* @strerror(i32 %11)
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = tail call i32 @read_vmstat(%struct.state* %0)
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %19
%23 = load i32, i32* @stderr
%24 = tail call i8* @strerror(i32 %20)
%25 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %19
ret void
}