#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*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open_output_file(char *);
int ptym_open(char *);
scalar_t__ spawn_utempter(int, char *);
int /*<<< orphan*/ spawn_who(int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char pts_name[32];
  int pts_master;
  int fd1, fd2;
  int rc = 0;
  if (argc < 3) {
    fprintf(stderr, "Usage: %s file1 file2\n", argv[0]);
    exit(1);
  }
  fd1 = open_output_file(argv[1]);
  fd2 = open_output_file(argv[2]);
  if ((pts_master = ptym_open(pts_name)) < 0) {
    fprintf(stderr, "ptym_open failed, exiting..\n");
    rc = 1;
    goto out;
  }
  if (spawn_utempter(pts_master, "add") != 0) {
    rc = 1;
    goto out;
  }
  (void)spawn_who(fd1);
  if (spawn_utempter(pts_master, "del") != 0) {
    rc = 1;
    goto out;
  }
  (void)spawn_who(fd2);
out:
  close(pts_master);
  close(fd1);
  close(fd2);
  exit(rc);
}


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,-0x40(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bf <main+0x4f>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <open_output_file@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <open_output_file@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rdi
call   1080 <ptym_open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    1217 <main+0xa7>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x40(%rbp)
jmp    1271 <main+0x101>
mov    -0x34(%rbp),%edi
lea    0xe13(%rip),%rsi
call   1050 <spawn_utempter@plt>
cmp    $0x0,%rax
je     123c <main+0xcc>
movl   $0x1,-0x40(%rbp)
jmp    1271 <main+0x101>
mov    -0x38(%rbp),%edi
call   1060 <spawn_who@plt>
mov    -0x34(%rbp),%edi
lea    0xdea(%rip),%rsi
call   1050 <spawn_utempter@plt>
cmp    $0x0,%rax
je     1269 <main+0xf9>
movl   $0x1,-0x40(%rbp)
jmp    1271 <main+0x101>
mov    -0x3c(%rbp),%edi
call   1060 <spawn_who@plt>
mov    -0x34(%rbp),%edi
call   1030 <close@plt>
mov    -0x38(%rbp),%edi
call   1030 <close@plt>
mov    -0x3c(%rbp),%edi
call   1030 <close@plt>
mov    -0x40(%rbp),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11a6 <main+0x36>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%rbx),%rdi
call   1070 <open_output_file@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1070 <open_output_file@plt>
mov    %eax,%r14d
mov    %rsp,%rdi
call   1080 <ptym_open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    11ea <main+0x7a>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
jmp    1227 <main+0xb7>
lea    0xe43(%rip),%rsi
mov    %ebp,%edi
call   1050 <spawn_utempter@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1227 <main+0xb7>
mov    %r15d,%edi
call   1060 <spawn_who@plt>
lea    0xe27(%rip),%rsi
mov    %ebp,%edi
call   1050 <spawn_utempter@plt>
test   %rax,%rax
jne    1227 <main+0xb7>
mov    %r14d,%edi
call   1060 <spawn_who@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1030 <close@plt>
mov    %r15d,%edi
call   1030 <close@plt>
mov    %r14d,%edi
call   1030 <close@plt>
mov    %ebx,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s file1 file2\0A\00"
@.str.1 = [29 x i8] c"ptym_open failed, exiting..\0A\00"
@.str.2 = [4 x i8] c"add\00"
@.str.3 = [4 x i8] c"del\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [32 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @open_output_file(i8* %23)
store i32 %24, i32* %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @open_output_file(i8* %27)
store i32 %28, i32* %9
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%30 = call i32 @ptym_open(i8* %29)
store i32 %30, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %20
%33 = load i32, i32* @stderr
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %10
br label %50
35: ; preds = %20
%36 = load i32, i32* %7
%37 = call i64 @spawn_utempter(i32 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
store i32 1, i32* %10
br label %50
40: ; preds = %35
%41 = load i32, i32* %8
%42 = call i32 @spawn_who(i32 %41)
%43 = load i32, i32* %7
%44 = call i64 @spawn_utempter(i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 1, i32* %10
br label %50
47: ; preds = %40
%48 = load i32, i32* %9
%49 = call i32 @spawn_who(i32 %48)
br label %50
50: ; preds = %47, %46, %39, %32
%51 = load i32, i32* %7
%52 = call i32 @close(i32 %51)
%53 = load i32, i32* %8
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
%57 = load i32, i32* %10
%58 = call i32 @exit(i32 %57)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Usage: %s file1 file2\0A\00"
@.str.1 = [29 x i8] c"ptym_open failed, exiting..\0A\00"
@.str.2 = [4 x i8] c"add\00"
@.str.3 = [4 x i8] c"del\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @open_output_file(i8* %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32 @open_output_file(i8* %16)
%18 = call i32 @ptym_open(i8* %4)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %32
23: ; preds = %11
%24 = call i64 @spawn_utempter(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = call i32 @spawn_who(i32 %14)
%28 = call i64 @spawn_utempter(i32 %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 @spawn_who(i32 %17)
br label %32
32: ; preds = %26, %23, %30, %20
%33 = phi i32 [ 1, %20 ], [ 0, %30 ], [ 1, %23 ], [ 1, %26 ]
%34 = call i32 @close(i32 %18)
%35 = call i32 @close(i32 %14)
%36 = call i32 @close(i32 %17)
%37 = call i32 @exit(i32 %33)
unreachable
}