#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*/ STDERR_FILENO;
int WEXITSTATUS(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ set_silent();
int /*<<< orphan*/ set_verbose();
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ tfail(char *);
int /*<<< orphan*/ tmsg(char *);
int /*<<< orphan*/ tpass(char *);
int /*<<< orphan*/ ttext(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ wait(int *);
int cli_1() {
  int fdn[2];
  pipe(fdn);
  if (fork() == 0) {
    dup2(fdn[1], STDERR_FILENO);
    set_verbose();
    set_silent();
    exit(2);
  } else {
    tmsg("cli_1 ");
    int wstat;
    wait(&wstat);
    if (WEXITSTATUS(wstat) != 1) {
      tfail("set_silent() did not check verbose option\n");
      return 1;
    } else {
      char errmsg[55], *experrmsg = "\x1B[1m"
                                    "\x1B[31m"
                                    "Error: Cannot be both silent and verbose\n"
                                    "\x1B[0m";
      read(fdn[0], errmsg, 55);
      errmsg[54] = '\0';
      if (strcmp(errmsg, experrmsg) == 0) {
        tpass("\n");
        return 0;
      } else {
        tfail("Message did not match expected.\n");
        ttext("Printed error message: %d %s\n", strlen(errmsg), errmsg);
        ttext("Expected error message: %d %s\n", strlen(experrmsg), experrmsg);
        return 1;
      }
    }
  }
}


x86 assembly (clang, -O0):
<cli_1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1110 <fork@plt>
cmp    $0x0,%rax
jne    123b <cli_1+0x4b>
mov    -0x8(%rbp),%edi
mov    0x2dc4(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    $0x0,%al
call   10f0 <set_verbose@plt>
mov    $0x0,%al
call   10c0 <set_silent@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>
lea    0xdbe(%rip),%rdi
call   10a0 <tmsg@plt>
lea    -0x10(%rbp),%rdi
call   1100 <wait@plt>
mov    -0x10(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x1,%eax
je     1279 <cli_1+0x89>
lea    0xd9f(%rip),%rdi
call   1070 <tfail@plt>
movl   $0x1,-0x4(%rbp)
jmp    1311 <cli_1+0x121>
lea    0xdb2(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x37,%edx
call   1060 <read@plt>
movb   $0x0,-0x1a(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x58(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12c8 <cli_1+0xd8>
lea    0xdd1(%rip),%rdi
call   1090 <tpass@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <cli_1+0x121>
lea    0xd9a(%rip),%rdi
call   1070 <tfail@plt>
lea    -0x50(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
lea    -0x50(%rbp),%rdx
lea    0xda0(%rip),%rdi
call   10d0 <ttext@plt>
mov    -0x58(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%esi
mov    -0x58(%rbp),%rdx
lea    0xda3(%rip),%rdi
call   10d0 <ttext@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cli_1>:
push   %rbx
sub    $0x50,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %rax,%rax
je     12d5 <cli_1+0xe5>
lea    0xdea(%rip),%rdi
call   10a0 <tmsg@plt>
lea    0x4(%rsp),%rdi
call   1100 <wait@plt>
mov    0x4(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x1,%eax
jne    12ae <cli_1+0xbe>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x37,%edx
call   1060 <read@plt>
movb   $0x0,0x46(%rsp)
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12c5 <cli_1+0xd5>
lea    0xe00(%rip),%rdi
call   1070 <tfail@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe08(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   10d0 <ttext@plt>
lea    0xd9f(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0xe06(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   10d0 <ttext@plt>
jmp    12ba <cli_1+0xca>
lea    0xd52(%rip),%rdi
call   1070 <tfail@plt>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbx
ret
lea    0xdbc(%rip),%rdi
call   1090 <tpass@plt>
xor    %eax,%eax
jmp    12bf <cli_1+0xcf>
mov    0xc(%rsp),%edi
mov    0x2d00(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
xor    %eax,%eax
call   10f0 <set_verbose@plt>
xor    %eax,%eax
call   10c0 <set_silent@plt>
mov    $0x2,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
@STDERR_FILENO = global i32 0
@.str = [7 x i8] c"cli_1 \00"
@.str.1 = [43 x i8] c"set_silent() did not check verbose option\0A\00"
@.str.2 = [55 x i8] c"\1B[1m\1B[31mError: Cannot be both silent and verbose\0A\1B[0m\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c"Message did not match expected.\0A\00"
@.str.5 = [30 x i8] c"Printed error message: %d %s\0A\00"
@.str.6 = [31 x i8] c"Expected error message: %d %s\0A\00"
define i32 @cli_1() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
%4 = alloca [55 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = load i32, i32* @STDERR_FILENO
%14 = call i32 @dup2(i32 %12, i32 %13)
%15 = call i32 (...) @set_verbose()
%16 = call i32 (...) @set_silent()
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %0
%19 = call i32 @tmsg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @wait(i32* %3)
%21 = load i32, i32* %3
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = call i32 @tfail(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %48
26: ; preds = %18
store i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8** %5
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%28 = load i32, i32* %27
%29 = getelementptr inbounds [55 x i8], [55 x i8]* %4, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 55)
%31 = getelementptr inbounds [55 x i8], [55 x i8]* %4, i64 0, i64 54
store i8 0, i8* %31
%32 = getelementptr inbounds [55 x i8], [55 x i8]* %4, i64 0, i64 0
%33 = load i8*, i8** %5
%34 = call i64 @strcmp(i8* %32, i8* %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %26
%37 = call i32 @tpass(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %48
38: ; preds = %26
%39 = call i32 @tfail(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%40 = getelementptr inbounds [55 x i8], [55 x i8]* %4, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = getelementptr inbounds [55 x i8], [55 x i8]* %4, i64 0, i64 0
%43 = call i32 @ttext(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %41, i8* %42)
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
%46 = load i8*, i8** %5
%47 = call i32 @ttext(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %45, i8* %46)
store i32 1, i32* %1
br label %48
48: ; preds = %38, %36, %24
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
@STDERR_FILENO = global i32 0
@.str = [7 x i8] c"cli_1 \00"
@.str.1 = [43 x i8] c"set_silent() did not check verbose option\0A\00"
@.str.2 = [55 x i8] c"\1B[1m\1B[31mError: Cannot be both silent and verbose\0A\1B[0m\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c"Message did not match expected.\0A\00"
@.str.5 = [30 x i8] c"Printed error message: %d %s\0A\00"
@.str.6 = [31 x i8] c"Expected error message: %d %s\0A\00"
define i32 @cli_1() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca [55 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = load i32, i32* @STDERR_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = call i32 (...) @set_verbose()
%15 = call i32 (...) @set_silent()
%16 = call i32 @exit(i32 2)
unreachable
17: ; preds = %0
%18 = call i32 @tmsg(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%19 = bitcast i32* %2 to i8*
%20 = call i32 @wait(i32* %2)
%21 = load i32, i32* %2
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %26, label %24
24: ; preds = %17
%25 = call i32 @tfail(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
br label %43
26: ; preds = %17
%27 = getelementptr inbounds [55 x i8], [55 x i8]* %3, i64 0, i64 0
%28 = load i32, i32* %5
%29 = call i32 @read(i32 %28, i8* %27, i32 55)
%30 = getelementptr inbounds [55 x i8], [55 x i8]* %3, i64 0, i64 54
store i8 0, i8* %30
%31 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @tpass(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %41
35: ; preds = %26
%36 = call i32 @tfail(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @strlen(i8* %27)
%38 = call i32 @ttext(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i32 %37, i8* %27)
%39 = call i32 @strlen(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @ttext(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i32 %39, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %41
41: ; preds = %35, %33
%42 = phi i32 [ 0, %33 ], [ 1, %35 ]
br label %43
43: ; preds = %41, %24
%44 = phi i32 [ 1, %24 ], [ %42, %41 ]
ret i32 %44
}