#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 */

/* Variables and functions */
char *getenv(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void ipm_get_job_id(char *id, int len) {
  char *s = 0;
  s = getenv("PBS_JOBID");
  if (!s)
    s = getenv("LOADL_STEP_ID");
  if (!s)
    s = getenv("SLURM_JOBID");
  if (!s)
    s = getenv("JOB_ID");
  if (!s)
    s = getenv("LSB_JOBID");
  if (!s) {
    strncpy(id, "unknown", len);
  } else {
    strncpy(id, s, len);
  }
}


x86 assembly (clang, -O0):
<ipm_get_job_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1162 <ipm_get_job_id+0x42>
lea    0xeb1(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117d <ipm_get_job_id+0x5d>
lea    0xea4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1198 <ipm_get_job_id+0x78>
lea    0xe95(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b3 <ipm_get_job_id+0x93>
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d6 <ipm_get_job_id+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe69(%rip),%rsi
call   1040 <strncpy@plt>
jmp    11e6 <ipm_get_job_id+0xc6>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <strncpy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipm_get_job_id>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xed1(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    117d <ipm_get_job_id+0x5d>
lea    0xeca(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    117d <ipm_get_job_id+0x5d>
lea    0xec7(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    117d <ipm_get_job_id+0x5d>
lea    0xec2(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
jne    117d <ipm_get_job_id+0x5d>
lea    0xeb8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1190 <ipm_get_job_id+0x70>
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <strncpy@plt>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
jmp    1183 <ipm_get_job_id+0x63>

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

LLVM IR (-O2):
@.str = [10 x i8] c"PBS_JOBID\00"
@.str.1 = [14 x i8] c"LOADL_STEP_ID\00"
@.str.2 = [12 x i8] c"SLURM_JOBID\00"
@.str.3 = [7 x i8] c"JOB_ID\00"
@.str.4 = [10 x i8] c"LSB_JOBID\00"
@.str.5 = [8 x i8] c"unknown\00"
define void @ipm_get_job_id(i8* %0, i32 %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = tail call i8* @getenv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %19
8: ; preds = %5
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %1)
br label %22
19: ; preds = %2, %5, %8, %11, %14
%20 = phi i8* [ %15, %14 ], [ %12, %11 ], [ %9, %8 ], [ %6, %5 ], [ %3, %2 ]
%21 = tail call i32 @strncpy(i8* %0, i8* %20, i32 %1)
br label %22
22: ; preds = %19, %17
ret void
}