#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 */
typedef int time_t;

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int time(int /*<<< orphan*/ *);
void get_wall_clock_used(char *stepid, char **hostname, int *wu, int *wh,
                         int *ws) {
  time_t curtime = time(NULL);
  char *JobStartTime = getenv("JobStartTime");
  char *JobTimeLimit = getenv("JobTimeLimit");
  int StartTime, TimeLimit;
  StartTime = curtime;
  TimeLimit = 1800;
  if (JobStartTime != NULL) {
    sscanf(JobStartTime, "%d", &StartTime);
  }
  if (JobTimeLimit != NULL) {
    sscanf(JobTimeLimit, "%d", &TimeLimit);
  }
  *wh = *ws = TimeLimit;
  *wu = curtime - StartTime;
  return;
}


x86 assembly (clang, -O0):
<get_wall_clock_used>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,-0x2c(%rbp)
lea    0xea1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x38(%rbp)
lea    0xe9e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x44(%rbp)
movl   $0x708,-0x48(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11a4 <get_wall_clock_used+0x74>
mov    -0x38(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x44(%rbp),%rdx
call   1050 <sscanf@plt>
cmpq   $0x0,-0x40(%rbp)
je     11c3 <get_wall_clock_used+0x93>
mov    -0x40(%rbp),%rdi
lea    0xe60(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0x48(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
sub    -0x44(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wall_clock_used>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%ebp
lea    0xeac(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r13
mov    %ebp,0x4(%rsp)
movl   $0x708,(%rsp)
test   %rbx,%rbx
je     118f <get_wall_clock_used+0x5f>
lea    0xe98(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
test   %r13,%r13
je     11ab <get_wall_clock_used+0x7b>
lea    0xe7f(%rip),%rsi
mov    %rsp,%rdx
mov    %r13,%rdi
call   1050 <sscanf@plt>
mov    (%rsp),%eax
jmp    11b0 <get_wall_clock_used+0x80>
mov    $0x708,%eax
mov    %eax,(%r15)
mov    %eax,(%r12)
sub    0x4(%rsp),%ebp
mov    %ebp,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"JobStartTime\00"
@.str.1 = [13 x i8] c"JobTimeLimit\00"
@.str.2 = [3 x i8] c"%d\00"
define void @get_wall_clock_used(i8* %0, i8** %1, i32* %2, i32* %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32* %4, i32** %10
%16 = call i32 @time(i32* null)
store i32 %16, i32* %11
%17 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %12
%18 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %18, i8** %13
%19 = load i32, i32* %11
store i32 %19, i32* %14
store i32 1800, i32* %15
%20 = load i8*, i8** %12
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %5
%23 = load i8*, i8** %12
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %14)
br label %25
25: ; preds = %22, %5
%26 = load i8*, i8** %13
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i8*, i8** %13
%30 = call i32 @sscanf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %15)
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %15
%33 = load i32*, i32** %10
store i32 %32, i32* %33
%34 = load i32*, i32** %9
store i32 %32, i32* %34
%35 = load i32, i32* %11
%36 = load i32, i32* %14
%37 = sub nsw i32 %35, %36
%38 = load i32*, i32** %8
store i32 %37, i32* %38
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"JobStartTime\00"
@.str.1 = [13 x i8] c"JobTimeLimit\00"
@.str.2 = [3 x i8] c"%d\00"
define void @get_wall_clock_used(i8* nocapture readnone %0, i8** nocapture readnone %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4) {
%6 = alloca i32
%7 = alloca i32
%8 = tail call i32 @time(i32* null)
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%10 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%11 = bitcast i32* %6 to i8*
%12 = bitcast i32* %7 to i8*
store i32 %8, i32* %6
store i32 1800, i32* %7
%13 = icmp eq i8* %9, null
br i1 %13, label %16, label %14
14: ; preds = %5
%15 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
br label %16
16: ; preds = %14, %5
%17 = icmp eq i8* %10, null
br i1 %17, label %21, label %18
18: ; preds = %16
%19 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%20 = load i32, i32* %7
br label %21
21: ; preds = %18, %16
%22 = phi i32 [ %20, %18 ], [ 1800, %16 ]
store i32 %22, i32* %4
store i32 %22, i32* %3
%23 = load i32, i32* %6
%24 = sub nsw i32 %8, %23
store i32 %24, i32* %2
ret void
}