#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 tms {
  void *tms_cstime;
  void *tms_cutime;
  void *tms_stime;
  void *tms_utime;
};
typedef unsigned long clock_t;
typedef int /*<<< orphan*/ b;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
void *atol(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ read(int, char *, int);
char *skip(char *);
clock_t times(struct tms *buf) {
  char b[200], *p;
  int f;
  unsigned long r;
  memset(b, 0, sizeof(b));
  f = open("/dev/cputime", O_RDONLY);
  if (f >= 0) {
    lseek(f, SEEK_SET, 0);
    read(f, b, sizeof(b));
    close(f);
  }
  p = b;
  if (buf)
    buf->tms_utime = atol(p);
  p = skip(p);
  if (buf)
    buf->tms_stime = atol(p);
  p = skip(p);
  r = atol(p);
  if (buf) {
    p = skip(p);
    buf->tms_cutime = atol(p);
    p = skip(p);
    buf->tms_cstime = atol(p);
  }
  return r;
}


x86 assembly (clang, -O0):
<times>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    0xe5e(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0xdc(%rbp)
cmpl   $0x0,-0xdc(%rbp)
jl     11f2 <times+0x82>
mov    -0xdc(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    -0xdc(%rbp),%edi
lea    -0xd0(%rbp),%rsi
mov    $0xc8,%edx
call   1070 <read@plt>
mov    -0xdc(%rbp),%edi
call   1060 <close@plt>
lea    -0xd0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1222 <times+0xb2>
mov    -0xd8(%rbp),%rdi
call   1080 <atol@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0xd8(%rbp),%rdi
call   1030 <skip@plt>
mov    %rax,-0xd8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1257 <times+0xe7>
mov    -0xd8(%rbp),%rdi
call   1080 <atol@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0xd8(%rbp),%rdi
call   1030 <skip@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
call   1080 <atol@plt>
mov    %rax,-0xe8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     12db <times+0x16b>
mov    -0xd8(%rbp),%rdi
call   1030 <skip@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
call   1080 <atol@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0xd8(%rbp),%rdi
call   1030 <skip@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
call   1080 <atol@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0xe8(%rbp),%rax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<times>:
push   %rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe63(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     11d0 <times+0x60>
mov    %eax,%ebp
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <lseek@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc8,%edx
call   1070 <read@plt>
mov    %ebp,%edi
call   1060 <close@plt>
test   %rbx,%rbx
je     11fd <times+0x8d>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1080 <atol@plt>
mov    %rax,0x18(%rbx)
mov    %rbp,%rdi
call   1030 <skip@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <atol@plt>
mov    %rax,0x10(%rbx)
jmp    1208 <times+0x98>
mov    %rsp,%rdi
call   1030 <skip@plt>
mov    %rax,%rbp
mov    %rbp,%rdi
call   1030 <skip@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <atol@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     124d <times+0xdd>
mov    %rbp,%rdi
call   1030 <skip@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <atol@plt>
mov    %rax,0x8(%rbx)
mov    %rbp,%rdi
call   1030 <skip@plt>
mov    %rax,%rdi
call   1080 <atol@plt>
mov    %rax,(%rbx)
mov    %r14,%rax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.tms = type { i8*, i8*, i8*, i8* }
@.str = [13 x i8] c"/dev/cputime\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i64 @times(%struct.tms* %0) {
%2 = alloca %struct.tms*
%3 = alloca [200 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store %struct.tms* %0, %struct.tms** %2
%7 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 200)
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %1
%14 = load i32, i32* %5
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 200)
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %13, %1
%23 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
store i8* %23, i8** %4
%24 = load %struct.tms*, %struct.tms** %2
%25 = icmp ne %struct.tms* %24, null
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %4
%28 = call i8* @atol(i8* %27)
%29 = load %struct.tms*, %struct.tms** %2
%30 = getelementptr inbounds %struct.tms, %struct.tms* %29, i32 0, i32 3
store i8* %28, i8** %30
br label %31
31: ; preds = %26, %22
%32 = load i8*, i8** %4
%33 = call i8* @skip(i8* %32)
store i8* %33, i8** %4
%34 = load %struct.tms*, %struct.tms** %2
%35 = icmp ne %struct.tms* %34, null
br i1 %35, label %36, label %41
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = call i8* @atol(i8* %37)
%39 = load %struct.tms*, %struct.tms** %2
%40 = getelementptr inbounds %struct.tms, %struct.tms* %39, i32 0, i32 2
store i8* %38, i8** %40
br label %41
41: ; preds = %36, %31
%42 = load i8*, i8** %4
%43 = call i8* @skip(i8* %42)
store i8* %43, i8** %4
%44 = load i8*, i8** %4
%45 = call i8* @atol(i8* %44)
%46 = ptrtoint i8* %45 to i64
store i64 %46, i64* %6
%47 = load %struct.tms*, %struct.tms** %2
%48 = icmp ne %struct.tms* %47, null
br i1 %48, label %49, label %62
49: ; preds = %41
%50 = load i8*, i8** %4
%51 = call i8* @skip(i8* %50)
store i8* %51, i8** %4
%52 = load i8*, i8** %4
%53 = call i8* @atol(i8* %52)
%54 = load %struct.tms*, %struct.tms** %2
%55 = getelementptr inbounds %struct.tms, %struct.tms* %54, i32 0, i32 1
store i8* %53, i8** %55
%56 = load i8*, i8** %4
%57 = call i8* @skip(i8* %56)
store i8* %57, i8** %4
%58 = load i8*, i8** %4
%59 = call i8* @atol(i8* %58)
%60 = load %struct.tms*, %struct.tms** %2
%61 = getelementptr inbounds %struct.tms, %struct.tms* %60, i32 0, i32 0
store i8* %59, i8** %61
br label %62
62: ; preds = %49, %41
%63 = load i64, i64* %6
ret i64 %63
}

LLVM IR (-O2):
%struct.tms = type { i8*, i8*, i8*, i8* }
@.str = [13 x i8] c"/dev/cputime\00"
@O_RDONLY = global i32 0
@SEEK_SET = global i32 0
define i64 @times(%struct.tms* writeonly %0) {
%2 = alloca [200 x i8]
%3 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 200)
%5 = load i32, i32* @O_RDONLY
%6 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %1
%9 = load i32, i32* @SEEK_SET
%10 = call i32 @lseek(i32 %6, i32 %9, i32 0)
%11 = call i32 @read(i32 %6, i8* %3, i32 200)
%12 = call i32 @close(i32 %6)
br label %13
13: ; preds = %8, %1
%14 = icmp eq %struct.tms* %0, null
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = call i8* @skip(i8* %3)
br label %23
17: ; preds = %13
%18 = call i8* @atol(i8* %3)
%19 = getelementptr inbounds %struct.tms, %struct.tms* %0, i64 0, i32 3
store i8* %18, i8** %19
%20 = call i8* @skip(i8* %3)
%21 = call i8* @atol(i8* %20)
%22 = getelementptr inbounds %struct.tms, %struct.tms* %0, i64 0, i32 2
store i8* %21, i8** %22
br label %23
23: ; preds = %15, %17
%24 = phi i8* [ %16, %15 ], [ %20, %17 ]
%25 = call i8* @skip(i8* %24)
%26 = call i8* @atol(i8* %25)
br i1 %14, label %34, label %27
27: ; preds = %23
%28 = call i8* @skip(i8* %25)
%29 = call i8* @atol(i8* %28)
%30 = getelementptr inbounds %struct.tms, %struct.tms* %0, i64 0, i32 1
store i8* %29, i8** %30
%31 = call i8* @skip(i8* %28)
%32 = call i8* @atol(i8* %31)
%33 = getelementptr inbounds %struct.tms, %struct.tms* %0, i64 0, i32 0
store i8* %32, i8** %33
br label %34
34: ; preds = %27, %23
%35 = ptrtoint i8* %26 to i64
ret i64 %35
}