#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ forkpty(int *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  ++argv;
  int pty;
  pid_t iskid = forkpty(&pty, NULL, NULL, NULL);
  if (iskid < 0)
    return -1;
  if (iskid)
    execvp(argv[0], argv);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <forkpty@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1170 <main+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    1192 <main+0x72>
cmpq   $0x0,-0x20(%rbp)
je     118b <main+0x6b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <execvp@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
add    $0x8,%rbx
xor    %r14d,%r14d
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <forkpty@plt>
test   %rax,%rax
js     1152 <main+0x32>
je     1158 <main+0x38>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1040 <execvp@plt>
jmp    1158 <main+0x38>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i32 1
store i8** %9, i8*** %5
%10 = call i64 @forkpty(i32* %6, i32* null, i32* null, i32* null)
store i64 %10, i64* %7
%11 = load i64, i64* %7
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %24
14: ; preds = %2
%15 = load i64, i64* %7
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = load i8**, i8*** %5
%22 = call i32 @execvp(i8* %20, i8** %21)
br label %23
23: ; preds = %17, %14
store i32 0, i32* %3
br label %24
24: ; preds = %23, %13
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = bitcast i32* %3 to i8*
%6 = call i64 @forkpty(i32* %3, i32* null, i32* null, i32* null)
%7 = icmp slt i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = icmp eq i64 %6, 0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = load i8*, i8** %4
%12 = call i32 @execvp(i8* %11, i8** %4)
br label %13
13: ; preds = %8, %10, %2
%14 = phi i32 [ -1, %2 ], [ 0, %10 ], [ 0, %8 ]
ret i32 %14
}