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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ show_rusage(struct rusage *);
int /*<<< orphan*/ show_rusage2(struct rusage *);
int /*<<< orphan*/ show_rusagehead();
int main() {
  struct rusage rusage;
  int ret = getrusage(RUSAGE_SELF, &rusage);
  if (ret) {
    perror("gerrusage");
    exit(EXIT_FAILURE);
  }
  show_rusage(&rusage);
  show_rusagehead();
  show_rusage2(&rusage);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1050 <getrusage@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11a8 <main+0x48>
lea    0xe6b(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1040 <show_rusage@plt>
mov    $0x0,%al
call   1080 <show_rusagehead@plt>
lea    -0x8(%rbp),%rdi
call   1030 <show_rusage2@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <getrusage@plt>
test   %eax,%eax
jne    11a0 <main+0x40>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <show_rusage@plt>
xor    %eax,%eax
call   1080 <show_rusagehead@plt>
mov    %rbx,%rdi
call   1030 <show_rusage2@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@.str = [10 x i8] c"gerrusage\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.rusage
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @RUSAGE_SELF
%5 = call i32 @getrusage(i32 %4, %struct.rusage* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @show_rusage(%struct.rusage* %2)
%14 = call i32 (...) @show_rusagehead()
%15 = call i32 @show_rusage2(%struct.rusage* %2)
ret i32 0
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
@RUSAGE_SELF = global i32 0
@.str = [10 x i8] c"gerrusage\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca %struct.rusage
%2 = bitcast %struct.rusage* %1 to i8*
%3 = load i32, i32* @RUSAGE_SELF
%4 = call i32 @getrusage(i32 %3, %struct.rusage* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = call i32 @show_rusage(%struct.rusage* %1)
%12 = call i32 (...) @show_rusagehead()
%13 = call i32 @show_rusage2(%struct.rusage* %1)
ret i32 0
}