#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 */
struct termios {
  int dummy;
};
struct stat {
  int st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
char *getenv(char *);
char **malloc(int);
int /*<<< orphan*/ memcpy(char **, char **, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ tcgetattr(int, struct termios *);
int main(int argc, char **argv) {
  struct termios term;
  struct stat statbuf;
  char *jar, **args;
  int n = 0;
  jar = getenv("YETI_JAR");
  if (!jar)
    jar = "/usr/share/yeti/yeti.jar";
  args = malloc((argc + 3) * sizeof(char *));
  if (!tcgetattr(1, &term) && !tcgetattr(0, &term) &&
      !stat("/usr/bin/rlwrap", &statbuf) && (statbuf.st_mode & 0700))
    args[n++] = "rlwrap";
  args[n++] = "java";
  args[n++] = "-jar";
  args[n++] = jar;
  memcpy(args + n, argv + 1, argc * sizeof(char *));
  execvp(args[0], args);
  perror(args[0]);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe6c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b3 <main+0x43>
lea    0xe5a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
add    $0x3,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
cmp    $0x0,%eax
jne    123c <main+0xcc>
xor    %edi,%edi
lea    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
cmp    $0x0,%eax
jne    123c <main+0xcc>
lea    0xe26(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%eax
jne    123c <main+0xcc>
mov    -0x20(%rbp),%eax
and    $0x1c0,%eax
cmp    $0x0,%eax
je     123c <main+0xcc>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
lea    0xdf3(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
lea    0xddd(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x34(%rbp)
movslq %ecx,%rcx
lea    0xdc5(%rip),%rdx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rdi
movslq -0x34(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <execvp@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe78(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
mov    %ebx,%r12d
shl    $0x3,%r12d
lea    0x18(,%rbx,8),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    $0x1,%edi
call   1070 <tcgetattr@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    11fa <main+0x8a>
xor    %ebp,%ebp
lea    0x8(%rsp),%rsi
xor    %edi,%edi
call   1070 <tcgetattr@plt>
test   %eax,%eax
jne    11fa <main+0x8a>
lea    0xe4e(%rip),%rdi
mov    %rsp,%rsi
call   1040 <stat@plt>
test   %eax,%eax
jne    11fa <main+0x8a>
movzwl (%rsp),%eax
test   $0x1c0,%eax
je     11fa <main+0x8a>
lea    0xe39(%rip),%rax
mov    %rax,(%rbx)
mov    $0x1,%ebp
test   %r15,%r15
lea    0xe05(%rip),%rax
cmovne %r15,%rax
mov    %ebp,%ecx
lea    0xe21(%rip),%rdx
mov    %rdx,(%rbx,%rcx,8)
or     $0x2,%ebp
lea    0xe18(%rip),%rdx
mov    %rdx,0x8(%rbx,%rcx,8)
mov    %rax,(%rbx,%rbp,8)
lea    (%rbx,%rcx,8),%rdi
add    $0x18,%rdi
add    $0x8,%r14
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1090 <execvp@plt>
mov    (%rbx),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
%struct.stat = type { i32 }
@.str = [9 x i8] c"YETI_JAR\00"
@.str.1 = [25 x i8] c"/usr/share/yeti/yeti.jar\00"
@.str.2 = [16 x i8] c"/usr/bin/rlwrap\00"
@.str.3 = [7 x i8] c"rlwrap\00"
@.str.4 = [5 x i8] c"java\00"
@.str.5 = [5 x i8] c"-jar\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca %struct.stat
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %15
15: ; preds = %14, %2
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 3
%18 = sext i32 %17 to i64
%19 = mul i64 %18, 8
%20 = trunc i64 %19 to i32
%21 = call i8** @malloc(i32 %20)
store i8** %21, i8*** %9
%22 = call i32 @tcgetattr(i32 1, %struct.termios* %6)
%23 = icmp ne i32 %22, 0
br i1 %23, label %41, label %24
24: ; preds = %15
%25 = call i32 @tcgetattr(i32 0, %struct.termios* %6)
%26 = icmp ne i32 %25, 0
br i1 %26, label %41, label %27
27: ; preds = %24
%28 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %7)
%29 = icmp ne i32 %28, 0
br i1 %29, label %41, label %30
30: ; preds = %27
%31 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%32 = load i32, i32* %31
%33 = and i32 %32, 448
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %30
%36 = load i8**, i8*** %9
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i8*, i8** %36, i64 %39
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %40
br label %41
41: ; preds = %35, %30, %27, %24, %15
%42 = load i8**, i8*** %9
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8*, i8** %42, i64 %45
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %46
%47 = load i8**, i8*** %9
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
%50 = sext i32 %48 to i64
%51 = getelementptr inbounds i8*, i8** %47, i64 %50
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %51
%52 = load i8*, i8** %8
%53 = load i8**, i8*** %9
%54 = load i32, i32* %10
%55 = add nsw i32 %54, 1
store i32 %55, i32* %10
%56 = sext i32 %54 to i64
%57 = getelementptr inbounds i8*, i8** %53, i64 %56
store i8* %52, i8** %57
%58 = load i8**, i8*** %9
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 1
%64 = load i32, i32* %4
%65 = sext i32 %64 to i64
%66 = mul i64 %65, 8
%67 = trunc i64 %66 to i32
%68 = call i32 @memcpy(i8** %61, i8** %63, i32 %67)
%69 = load i8**, i8*** %9
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %9
%73 = call i32 @execvp(i8* %71, i8** %72)
%74 = load i8**, i8*** %9
%75 = getelementptr inbounds i8*, i8** %74, i64 0
%76 = load i8*, i8** %75
%77 = call i32 @perror(i8* %76)
ret i32 1
}

LLVM IR (-O2):
%struct.termios = type { i32 }
%struct.stat = type { i32 }
@.str = [9 x i8] c"YETI_JAR\00"
@.str.1 = [25 x i8] c"/usr/share/yeti/yeti.jar\00"
@.str.2 = [16 x i8] c"/usr/bin/rlwrap\00"
@.str.3 = [7 x i8] c"rlwrap\00"
@.str.4 = [5 x i8] c"java\00"
@.str.5 = [5 x i8] c"-jar\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.termios
%4 = alloca %struct.stat
%5 = bitcast %struct.termios* %3 to i8*
%6 = bitcast %struct.stat* %4 to i8*
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%8 = shl i32 %0, 3
%9 = add i32 %8, 24
%10 = tail call i8** @malloc(i32 %9)
%11 = call i32 @tcgetattr(i32 1, %struct.termios* %3)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = call i32 @stat(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %4)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, 448
%23 = icmp eq i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %19
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %10
br label %25
25: ; preds = %24, %19, %16, %13, %2
%26 = phi i32 [ 0, %2 ], [ 0, %13 ], [ 0, %16 ], [ 1, %24 ], [ 0, %19 ]
%27 = icmp eq i8* %7, null
%28 = select i1 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %7
%29 = add nuw nsw i32 %26, 1
%30 = zext i32 %26 to i64
%31 = getelementptr inbounds i8*, i8** %10, i64 %30
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %31
%32 = or i32 %26, 2
%33 = zext i32 %29 to i64
%34 = getelementptr inbounds i8*, i8** %10, i64 %33
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %34
%35 = add nuw nsw i32 %26, 3
%36 = zext i32 %32 to i64
%37 = getelementptr inbounds i8*, i8** %10, i64 %36
store i8* %28, i8** %37
%38 = zext i32 %35 to i64
%39 = getelementptr inbounds i8*, i8** %10, i64 %38
%40 = getelementptr inbounds i8*, i8** %1, i64 1
%41 = call i32 @memcpy(i8** %39, i8** %40, i32 %8)
%42 = load i8*, i8** %10
%43 = call i32 @execvp(i8* %42, i8** %10)
%44 = load i8*, i8** %10
%45 = call i32 @perror(i8* %44)
ret i32 1
}