#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 int /*<<< orphan*/ pid;

/* Variables and functions */
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ TIOCNOTTY;
int getpid();
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int open_socket(char *);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ send_fd(int /*<<< orphan*/, int, int /*<<< orphan*/ *,
                           int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char **argv) {
  int fd, pid;
  if ((argc > 1) && !strcmp(argv[1], "-uml-socket")) {
    fd = open_socket(argv[2]);
  } else {
    fd = 3;
  }
  signal(SIGHUP, SIG_IGN);
  if (ioctl(0, TIOCNOTTY, 0) < 0)
    perror("TIOCNOTTY failed in port-helper, check UML's exec call for xterm "
           "or telnetd");
  pid = getpid();
  send_fd(0, fd, NULL, 0, &pid, sizeof(pid));
  pause();
  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)
cmpl   $0x1,-0x8(%rbp)
jle    11d2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11d2 <main+0x52>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <open_socket@plt>
mov    %eax,-0x14(%rbp)
jmp    11d9 <main+0x59>
movl   $0x3,-0x14(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
mov    %edx,%edi
call   1060 <ioctl@plt>
cmp    $0x0,%rax
jge    1218 <main+0x98>
lea    0xdf9(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%esi
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%r8
mov    $0x4,%r9d
mov    %ecx,%edi
call   1050 <send_fd@plt>
mov    $0x0,%al
call   1090 <pause@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3,%ebp
cmp    $0x2,%edi
jl     11af <main+0x2f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe65(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    11af <main+0x2f>
mov    0x10(%rbx),%rdi
call   1040 <open_socket@plt>
mov    %eax,%ebp
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    0x2e19(%rip),%rax
mov    (%rax),%esi
call   1080 <signal@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
xor    %edx,%edx
call   1060 <ioctl@plt>
test   %rax,%rax
js     1210 <main+0x90>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x4(%rsp)
lea    0x4(%rsp),%r8
xor    %edi,%edi
mov    %ebp,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    $0x4,%r9d
call   1050 <send_fd@plt>
xor    %eax,%eax
call   1090 <pause@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdf5(%rip),%rdi
call   10a0 <perror@plt>
jmp    11dd <main+0x5d>

LLVM IR (-O0):
@.str = [12 x i8] c"-uml-socket\00"
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@TIOCNOTTY = global i32 0
@.str.1 = [76 x i8] c"TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @open_socket(i8* %19)
store i32 %20, i32* %6
br label %22
21: ; preds = %10, %2
store i32 3, i32* %6
br label %22
22: ; preds = %21, %16
%23 = load i32, i32* @SIGHUP
%24 = load i32, i32* @SIG_IGN
%25 = call i32 @signal(i32 %23, i32 %24)
%26 = load i32, i32* @TIOCNOTTY
%27 = call i64 @ioctl(i32 0, i32 %26, i32 0)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %22
%30 = call i32 @perror(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %22
%32 = call i32 (...) @getpid()
store i32 %32, i32* %7
%33 = load i32, i32* %6
%34 = call i32 @send_fd(i32 0, i32 %33, i32* null, i32 0, i32* %7, i32 4)
%35 = call i32 (...) @pause()
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"-uml-socket\00"
@SIGHUP = global i32 0
@SIG_IGN = global i32 0
@TIOCNOTTY = global i32 0
@.str.1 = [76 x i8] c"TIOCNOTTY failed in port-helper, check UML's exec call for xterm or telnetd\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @open_socket(i8* %13)
br label %15
15: ; preds = %2, %6, %11
%16 = phi i32 [ %14, %11 ], [ 3, %6 ], [ 3, %2 ]
%17 = load i32, i32* @SIGHUP
%18 = load i32, i32* @SIG_IGN
%19 = tail call i32 @signal(i32 %17, i32 %18)
%20 = load i32, i32* @TIOCNOTTY
%21 = tail call i64 @ioctl(i32 0, i32 %20, i32 0)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = tail call i32 @perror(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %15
%26 = tail call i32 (...) @getpid()
store i32 %26, i32* %3
%27 = call i32 @send_fd(i32 0, i32 %16, i32* null, i32 0, i32* %3, i32 4)
%28 = call i32 (...) @pause()
ret i32 0
}