#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 *dupstr(char *);
char *getenv(char *);
scalar_t__ strcmp(char *, char *);
char *get_jt_path(int argc, char **argv) {
  int i;
  char *ps;
  for (i = 1; i < argc; i++) {
    if (0 == strcmp(argv[i], "-JTPATH")) {
      return dupstr(argv[i + 1]);
    }
  }
  ps = getenv("-JTPATH" + 1);
  return ps ? dupstr(ps) : 0;
}


x86 assembly (clang, -O0):
<get_jt_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11aa <get_jt_path+0x7a>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe9b(%rip),%rsi
call   1040 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1197 <get_jt_path+0x67>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <dupstr@plt>
mov    %rax,-0x8(%rbp)
jmp    11ee <get_jt_path+0xbe>
jmp    119c <get_jt_path+0x6c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <get_jt_path+0x16>
lea    0xe4f(%rip),%rdi
add    $0x1,%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11db <get_jt_path+0xab>
mov    -0x28(%rbp),%rdi
call   1050 <dupstr@plt>
mov    %rax,-0x30(%rbp)
jmp    11e6 <get_jt_path+0xb6>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11e6 <get_jt_path+0xb6>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_jt_path>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     116a <get_jt_path+0x3a>
mov    %rsi,%r15
mov    %edi,%r12d
mov    $0x1,%ebx
lea    0xeb1(%rip),%r14
nop
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     1180 <get_jt_path+0x50>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <get_jt_path+0x20>
lea    0xe90(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1195 <get_jt_path+0x65>
mov    %rax,%rdi
jmp    1185 <get_jt_path+0x55>
mov    0x8(%r15,%rbx,8),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <dupstr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"-JTPATH\00"
define i8* @get_jt_path(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %8
8: ; preds = %29, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %32
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 0, %18
br i1 %19, label %20, label %28
20: ; preds = %12
%21 = load i8**, i8*** %5
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %21, i64 %24
%26 = load i8*, i8** %25
%27 = call i8* @dupstr(i8* %26)
store i8* %27, i8** %3
br label %42
28: ; preds = %12
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %8
32: ; preds = %8
%33 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 1))
store i8* %33, i8** %7
%34 = load i8*, i8** %7
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i8*, i8** %7
%38 = call i8* @dupstr(i8* %37)
br label %40
39: ; preds = %32
br label %40
40: ; preds = %39, %36
%41 = phi i8* [ %38, %36 ], [ null, %39 ]
store i8* %41, i8** %3
br label %42
42: ; preds = %40, %20
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [8 x i8] c"-JTPATH\00"
define i8* @get_jt_path(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %20
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %18
%7 = phi i64 [ 1, %4 ], [ %12, %18 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
%12 = add nuw i64 %7, 1
br i1 %11, label %13, label %18
13: ; preds = %6
%14 = and i64 %12, 4294967295
%15 = getelementptr inbounds i8*, i8** %1, i64 %14
%16 = load i8*, i8** %15
%17 = tail call i8* @dupstr(i8* %16)
br label %25
18: ; preds = %6
%19 = icmp eq i64 %12, %5
br i1 %19, label %20, label %6
20: ; preds = %18, %2
%21 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 1))
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i8* @dupstr(i8* %21)
br label %25
25: ; preds = %23, %20, %13
%26 = phi i8* [ %17, %13 ], [ %24, %23 ], [ null, %20 ]
ret i8* %26
}