#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *env_get_job_id(void) {
  char var[80] = "PBS_JOBID";
  char *job_id = getenv(var);
  if (job_id != NULL) {
    char *tmp = (char *)malloc((1 + strlen(job_id)) * sizeof(char));
    if (tmp == NULL)
      errx(EXIT_FAILURE, "can not allocate job ID");
    strcpy(tmp, job_id);
    return tmp;
  } else {
    return NULL;
  }
}


x86 assembly (clang, -O0):
<env_get_job_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    -0x60(%rbp),%rdi
lea    0xe8d(%rip),%rsi
mov    $0x50,%edx
call   1070 <memcpy@plt>
lea    -0x60(%rbp),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     11ec <env_get_job_id+0x8c>
mov    -0x68(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
jne    11d2 <env_get_job_id+0x72>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
call   1060 <errx@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x70(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11f4 <env_get_job_id+0x94>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<env_get_job_id>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11a2 <env_get_job_id+0x52>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1195 <env_get_job_id+0x45>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1060 <errx@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
jmp    11a4 <env_get_job_id+0x54>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.env_get_job_id.var = [80 x i8] c"PBS_JOBID\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_FAILURE = global i32 0
@.str = [24 x i8] c"can not allocate job ID\00"
define i8* @env_get_job_id() {
%1 = alloca i8*
%2 = alloca [80 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast [80 x i8]* %2 to i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%7 = call i8* @getenv(i8* %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 1, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @errx(i32 %22, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %21, %10
%25 = load i8*, i8** %4
%26 = load i8*, i8** %3
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %4
store i8* %28, i8** %1
br label %30
29: ; preds = %0
store i8* null, i8** %1
br label %30
30: ; preds = %29, %24
%31 = load i8*, i8** %1
ret i8* %31
}

LLVM IR (-O2):
@__const.env_get_job_id.var = [80 x i8] c"PBS_JOBID\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@EXIT_FAILURE = global i32 0
@.str = [24 x i8] c"can not allocate job ID\00"
define i8* @env_get_job_id() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @__const.env_get_job_id.var, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %14, label %3
3: ; preds = %0
%4 = tail call i32 @strlen(i8* %1)
%5 = add nsw i32 %4, 1
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @errx(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %3
%13 = tail call i32 @strcpy(i8* %7, i8* %1)
br label %14
14: ; preds = %0, %12
%15 = phi i8* [ %7, %12 ], [ null, %0 ]
ret i8* %15
}