#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ system(char *);
long int GetSchedTime(char *host, char *part, long int hms, int np,
                      long int onError) {
  int h, m, s;
  FILE *pIn;
  char cmd[1000], schFile[1000], schTime[1000], timestr[1000];
  long int sch = 0;
  long int backfill_interval = 0;
  int pid = getpid();
  sprintf(schFile, "%s/sched.%d", "/tmp", pid);
  h = hms / (60 * 60);
  m = (hms - h * 60 * 60) / 60;
  s = (hms - h * 60 * 60 - m * 60);
  sprintf(timestr, "%02d:%02d:%02d", h, m, s);
  sprintf(cmd,
          "srun --test-only --nodes=1 --nodelist=%s --partition=%s --ntasks=%d "
          "--time=%s 2>&1 | sed 's/^srun: Job [0-9]* to start at //g' | sed "
          "'s/ using [0-9]* processors on %s//g' > %s",
          host, part, np, timestr, host, schFile);
  system(cmd);
  pIn = fopen(schFile, "r");
  fscanf(pIn, "%s", schTime);
  fclose(pIn);
  if (strstr(schTime, "allocation") != NULL) {
    sch = onError;
  } else {
    sprintf(cmd, "date --date=%s +%%s > %s", schTime, schFile);
    system(cmd);
    pIn = fopen(schFile, "r");
    fscanf(pIn, "%ld", &sch);
    fclose(pIn);
  }
  sprintf(cmd, "rm -f %s", schFile);
  system(cmd);
  sch -= backfill_interval;
  if (sch < 0)
    sch = 0;
  return sch;
}


x86 assembly (clang, -O0):
<GetSchedTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
movq   $0x0,-0x1008(%rbp)
movq   $0x0,-0x1010(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1014(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x1014(%rbp),%ecx
lea    0xe3b(%rip),%rsi
lea    0xe40(%rip),%rdx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    $0xe10,%ecx
cqto
idiv   %rcx
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3c,-0x2c(%rbp),%ecx
imul   $0x3c,%ecx,%ecx
movslq %ecx,%rcx
sub    %rcx,%rax
mov    $0x3c,%ecx
cqto
idiv   %rcx
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3c,-0x2c(%rbp),%ecx
imul   $0x3c,%ecx,%ecx
movslq %ecx,%rcx
sub    %rcx,%rax
imul   $0x3c,-0x30(%rbp),%ecx
movslq %ecx,%rcx
sub    %rcx,%rax
mov    %eax,-0x34(%rbp)
lea    -0x1000(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x430(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    -0x1000(%rbp),%r9
mov    -0x8(%rbp),%r10
lea    -0x820(%rbp),%rax
lea    0xdb5(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1050 <system@plt>
lea    -0x820(%rbp),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0xc10(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0xc10(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12ed <GetSchedTime+0x17d>
mov    -0x28(%rbp),%rax
mov    %rax,-0x1008(%rbp)
jmp    1355 <GetSchedTime+0x1e5>
lea    -0x430(%rbp),%rdi
lea    -0xc10(%rbp),%rdx
lea    -0x820(%rbp),%rcx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1050 <system@plt>
lea    -0x820(%rbp),%rdi
lea    0xda6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdb8(%rip),%rsi
lea    -0x1008(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x430(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x430(%rbp),%rdi
call   1050 <system@plt>
mov    -0x1010(%rbp),%rcx
mov    -0x1008(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x1008(%rbp)
cmpq   $0x0,-0x1008(%rbp)
jge    13ae <GetSchedTime+0x23e>
movq   $0x0,-0x1008(%rbp)
mov    -0x1008(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetSchedTime>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfc8,%rsp
mov    %r8,0x8(%rsp)
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    %rsi,%r13
mov    %rdi,%r14
movq   $0x0,(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe58(%rip),%rsi
lea    0xe5d(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1080 <sprintf@plt>
movabs $0x48d159e26af37c05,%rcx
59 d1 48
mov    %rbp,%rax
imul   %rcx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0xa,%rbx
add    %rax,%rbx
movabs $0xe1000000000,%rax
imul   %rbx,%rax
sar    $0x20,%rax
sub    %rax,%rbp
movabs $0x8888888888888889,%rcx
88 88 88
mov    %rbp,%rax
imul   %rcx
mov    %rdx,%rcx
add    %rbp,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x5,%rcx
add    %rax,%rcx
movabs $0x3c00000000,%rax
imul   %rcx,%rax
shr    $0x20,%rax
sub    %eax,%ebp
lea    0xddf(%rip),%rsi
lea    0xbe0(%rsp),%r15
mov    %r15,%rdi
mov    %ebx,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xdd0(%rip),%rsi
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r13,%rcx
mov    %r12d,%r8d
mov    %r15,%r9
xor    %eax,%eax
lea    0x10(%rsp),%rbp
push   %rbp
push   %r14
call   1080 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe32(%rip),%rsi
lea    0x7f0(%rsp),%rbp
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe13(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strstr@plt>
test   %rax,%rax
je     12d7 <GetSchedTime+0x167>
mov    0x8(%rsp),%rax
mov    %rax,(%rsp)
jmp    1336 <GetSchedTime+0x1c6>
lea    0xdff(%rip),%rsi
lea    0x400(%rsp),%rbx
lea    0x7f0(%rsp),%rdx
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
lea    0xdc1(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xdd5(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1060 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xdbd(%rip),%rsi
xor    %ebx,%ebx
lea    0x400(%rsp),%rbp
lea    0x10(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbp,%rdi
call   1050 <system@plt>
mov    (%rsp),%rax
test   %rax,%rax
cmovns %rax,%rbx
mov    %rbx,%rax
add    $0xfc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s/sched.%d\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [15 x i8] c"%02d:%02d:%02d\00"
@.str.3 = [176 x i8] c"srun --test-only --nodes=1 --nodelist=%s --partition=%s --ntasks=%d --time=%s 2>&1 | sed 's/^srun: Job [0-9]* to start at //g' | sed 's/ using [0-9]* processors on %s//g' > %s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [11 x i8] c"allocation\00"
@.str.7 = [25 x i8] c"date --date=%s +%%s > %s\00"
@.str.8 = [4 x i8] c"%ld\00"
@.str.9 = [9 x i8] c"rm -f %s\00"
define i64 @GetSchedTime(i8* %0, i8* %1, i64 %2, i32 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32*
%15 = alloca [1000 x i8]
%16 = alloca [1000 x i8]
%17 = alloca [1000 x i8]
%18 = alloca [1000 x i8]
%19 = alloca i64
%20 = alloca i64
%21 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i32 %3, i32* %9
store i64 %4, i64* %10
store i64 0, i64* %19
store i64 0, i64* %20
%22 = call i32 (...) @getpid()
store i32 %22, i32* %21
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%24 = load i32, i32* %21
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i64, i64* %8
%27 = sdiv i64 %26, 3600
%28 = trunc i64 %27 to i32
store i32 %28, i32* %11
%29 = load i64, i64* %8
%30 = load i32, i32* %11
%31 = mul nsw i32 %30, 60
%32 = mul nsw i32 %31, 60
%33 = sext i32 %32 to i64
%34 = sub nsw i64 %29, %33
%35 = sdiv i64 %34, 60
%36 = trunc i64 %35 to i32
store i32 %36, i32* %12
%37 = load i64, i64* %8
%38 = load i32, i32* %11
%39 = mul nsw i32 %38, 60
%40 = mul nsw i32 %39, 60
%41 = sext i32 %40 to i64
%42 = sub nsw i64 %37, %41
%43 = load i32, i32* %12
%44 = mul nsw i32 %43, 60
%45 = sext i32 %44 to i64
%46 = sub nsw i64 %42, %45
%47 = trunc i64 %46 to i32
store i32 %47, i32* %13
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %18, i64 0, i64 0
%49 = load i32, i32* %11
%50 = load i32, i32* %12
%51 = load i32, i32* %13
%52 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %49, i32 %50, i32 %51)
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%54 = load i8*, i8** %6
%55 = load i8*, i8** %7
%56 = load i32, i32* %9
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %18, i64 0, i64 0
%58 = load i8*, i8** %6
%59 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%60 = call i32 (i8*, i8*, ...) @sprintf(i8* %53, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str.3, i64 0, i64 0), i8* %54, i8* %55, i32 %56, i8* %57, i8* %58, i8* %59)
%61 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%62 = call i32 @system(i8* %61)
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%64 = call i32* @fopen(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %64, i32** %14
%65 = load i32*, i32** %14
%66 = getelementptr inbounds [1000 x i8], [1000 x i8]* %17, i64 0, i64 0
%67 = call i32 (i32*, i8*, ...) @fscanf(i32* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %66)
%68 = load i32*, i32** %14
%69 = call i32 @fclose(i32* %68)
%70 = getelementptr inbounds [1000 x i8], [1000 x i8]* %17, i64 0, i64 0
%71 = call i32* @strstr(i8* %70, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%72 = icmp ne i32* %71, null
br i1 %72, label %73, label %75
73: ; preds = %5
%74 = load i64, i64* %10
store i64 %74, i64* %19
br label %88
75: ; preds = %5
%76 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%77 = getelementptr inbounds [1000 x i8], [1000 x i8]* %17, i64 0, i64 0
%78 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%79 = call i32 (i8*, i8*, ...) @sprintf(i8* %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %77, i8* %78)
%80 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%81 = call i32 @system(i8* %80)
%82 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%83 = call i32* @fopen(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %83, i32** %14
%84 = load i32*, i32** %14
%85 = call i32 (i32*, i8*, ...) @fscanf(i32* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %19)
%86 = load i32*, i32** %14
%87 = call i32 @fclose(i32* %86)
br label %88
88: ; preds = %75, %73
%89 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%90 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%91 = call i32 (i8*, i8*, ...) @sprintf(i8* %89, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %90)
%92 = getelementptr inbounds [1000 x i8], [1000 x i8]* %15, i64 0, i64 0
%93 = call i32 @system(i8* %92)
%94 = load i64, i64* %20
%95 = load i64, i64* %19
%96 = sub nsw i64 %95, %94
store i64 %96, i64* %19
%97 = load i64, i64* %19
%98 = icmp slt i64 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %88
store i64 0, i64* %19
br label %100
100: ; preds = %99, %88
%101 = load i64, i64* %19
ret i64 %101
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s/sched.%d\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [15 x i8] c"%02d:%02d:%02d\00"
@.str.3 = [176 x i8] c"srun --test-only --nodes=1 --nodelist=%s --partition=%s --ntasks=%d --time=%s 2>&1 | sed 's/^srun: Job [0-9]* to start at //g' | sed 's/ using [0-9]* processors on %s//g' > %s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [11 x i8] c"allocation\00"
@.str.7 = [25 x i8] c"date --date=%s +%%s > %s\00"
@.str.8 = [4 x i8] c"%ld\00"
@.str.9 = [9 x i8] c"rm -f %s\00"
define i64 @GetSchedTime(i8* %0, i8* %1, i64 %2, i32 %3, i64 %4) {
%6 = alloca [1000 x i8]
%7 = alloca [1000 x i8]
%8 = alloca [1000 x i8]
%9 = alloca [1000 x i8]
%10 = alloca i64
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%15 = bitcast i64* %10 to i8*
store i64 0, i64* %10
%16 = tail call i32 (...) @getpid()
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = sdiv i64 %2, 3600
%19 = trunc i64 %18 to i32
%20 = mul i64 %18, 15461882265600
%21 = ashr exact i64 %20, 32
%22 = sub nsw i64 %2, %21
%23 = sdiv i64 %22, 60
%24 = trunc i64 %23 to i32
%25 = mul i64 %23, 257698037760
%26 = lshr exact i64 %25, 32
%27 = sub i64 %22, %26
%28 = trunc i64 %27 to i32
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19, i32 %24, i32 %28)
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([176 x i8], [176 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1, i32 %3, i8* %14, i8* %0, i8* %12)
%31 = call i32 @system(i8* %11)
%32 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 (i32*, i8*, ...) @fscanf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %13)
%34 = call i32 @fclose(i32* %32)
%35 = call i32* @strstr(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp eq i32* %35, null
br i1 %36, label %38, label %37
37: ; preds = %5
store i64 %4, i64* %10
br label %44
38: ; preds = %5
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %13, i8* %12)
%40 = call i32 @system(i8* %11)
%41 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (i32*, i8*, ...) @fscanf(i32* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64* %10)
%43 = call i32 @fclose(i32* %41)
br label %44
44: ; preds = %38, %37
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i8* %12)
%46 = call i32 @system(i8* %11)
%47 = load i64, i64* %10
%48 = icmp sgt i64 %47, 0
%49 = select i1 %48, i64 %47, i64 0
ret i64 %49
}