#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*/ holdit();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ println(char const *);
int /*<<< orphan*/ reset_colors();
int /*<<< orphan*/ sgr(char *);
int /*<<< orphan*/ vt_move(int, int);
int test_SGR_0(const char *the_title) {
  vt_move(1, 1);
  println(the_title);
  println("");
  println("ECMA-48 states that SGR 0 \"cancels the effect of any preceding "
          "occurrence");
  println("of SGR in the data stream regardless of the setting of the graphic "
          "rendition");
  println("combination mode (GRCM)\".");
  println("");
  println("");
  reset_colors();
  printf("You should see only black:");
  sgr("30;40");
  printf("SGR 30 and SGR 40 don't work");
  reset_colors();
  println(":up to here");
  reset_colors();
  printf("You should see only white:");
  sgr("37;47");
  printf("SGR 37 and SGR 47 don't work");
  reset_colors();
  println(":up to here");
  reset_colors();
  printf("You should see text here: ");
  sgr("30;40");
  sgr("0");
  printf("SGR 0 reset works (explicit 0)");
  println("");
  reset_colors();
  printf("................and here: ");
  sgr("37;47");
  sgr("");
  printf("SGR 0 reset works (default param)");
  println("");
  reset_colors();
  holdit();
  return 0;
}


x86 assembly (clang, -O0):
<test_SGR_0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x1,%esi
mov    %esi,%edi
call   1050 <vt_move@plt>
mov    -0x8(%rbp),%rdi
call   1060 <println@plt>
lea    0x1005(%rip),%rdi
call   1060 <println@plt>
lea    0xe6c(%rip),%rdi
call   1060 <println@plt>
lea    0xeaa(%rip),%rdi
call   1060 <println@plt>
lea    0xeeb(%rip),%rdi
call   1060 <println@plt>
lea    0xfd5(%rip),%rdi
call   1060 <println@plt>
lea    0xfc9(%rip),%rdi
call   1060 <println@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xeda(%rip),%rdi
call   1040 <printf@plt>
lea    0xee9(%rip),%rdi
call   1070 <sgr@plt>
lea    0xee3(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xeed(%rip),%rdi
call   1060 <println@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xee6(%rip),%rdi
call   1040 <printf@plt>
lea    0xef5(%rip),%rdi
call   1070 <sgr@plt>
lea    0xeef(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xeaf(%rip),%rdi
call   1060 <println@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xee6(%rip),%rdi
call   1040 <printf@plt>
lea    0xe6d(%rip),%rdi
call   1070 <sgr@plt>
lea    0xe65(%rip),%rdi
call   1070 <sgr@plt>
lea    0xedd(%rip),%rdi
call   1040 <printf@plt>
lea    0xf0a(%rip),%rdi
call   1060 <println@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
lea    0xedd(%rip),%rdi
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1070 <sgr@plt>
lea    0xedf(%rip),%rdi
call   1070 <sgr@plt>
lea    0xed4(%rip),%rdi
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
call   1060 <println@plt>
mov    $0x0,%al
call   1030 <reset_colors@plt>
mov    $0x0,%al
call   1080 <holdit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_SGR_0>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x1,%edi
mov    $0x1,%esi
call   1050 <vt_move@plt>
mov    %rbx,%rdi
call   1060 <println@plt>
lea    0x1004(%rip),%r12
mov    %r12,%rdi
call   1060 <println@plt>
lea    0xe68(%rip),%rdi
call   1060 <println@plt>
lea    0xea6(%rip),%rdi
call   1060 <println@plt>
lea    0xee7(%rip),%rdi
call   1060 <println@plt>
mov    %r12,%rdi
call   1060 <println@plt>
mov    %r12,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
lea    0xede(%rip),%rdi
call   1040 <printf@plt>
lea    0xeed(%rip),%r14
mov    %r14,%rdi
call   1070 <sgr@plt>
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
lea    0xeee(%rip),%rbx
mov    %rbx,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
lea    0xef3(%rip),%r15
mov    %r15,%rdi
call   1070 <sgr@plt>
lea    0xeea(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
mov    %rbx,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
lea    0xee5(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1070 <sgr@plt>
lea    0xe68(%rip),%rdi
call   1070 <sgr@plt>
lea    0xee0(%rip),%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
lea    0xee4(%rip),%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1070 <sgr@plt>
mov    %r12,%rdi
call   1070 <sgr@plt>
lea    0xee3(%rip),%rdi
call   1040 <printf@plt>
mov    %r12,%rdi
call   1060 <println@plt>
xor    %eax,%eax
call   1030 <reset_colors@plt>
xor    %eax,%eax
call   1080 <holdit@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [74 x i8] c"ECMA-48 states that SGR 0 \22cancels the effect of any preceding occurrence\00"
@.str.2 = [77 x i8] c"of SGR in the data stream regardless of the setting of the graphic rendition\00"
@.str.3 = [26 x i8] c"combination mode (GRCM)\22.\00"
@.str.4 = [27 x i8] c"You should see only black:\00"
@.str.5 = [6 x i8] c"30;40\00"
@.str.6 = [29 x i8] c"SGR 30 and SGR 40 don't work\00"
@.str.7 = [12 x i8] c":up to here\00"
@.str.8 = [27 x i8] c"You should see only white:\00"
@.str.9 = [6 x i8] c"37;47\00"
@.str.10 = [29 x i8] c"SGR 37 and SGR 47 don't work\00"
@.str.11 = [27 x i8] c"You should see text here: \00"
@.str.12 = [2 x i8] c"0\00"
@.str.13 = [31 x i8] c"SGR 0 reset works (explicit 0)\00"
@.str.14 = [27 x i8] c"................and here: \00"
@.str.15 = [34 x i8] c"SGR 0 reset works (default param)\00"
define i32 @test_SGR_0(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 @vt_move(i32 1, i32 1)
%4 = load i8*, i8** %2
%5 = call i32 @println(i8* %4)
%6 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @println(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @println(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @println(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (...) @reset_colors()
%13 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%14 = call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%16 = call i32 (...) @reset_colors()
%17 = call i32 @println(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%18 = call i32 (...) @reset_colors()
%19 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%20 = call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%22 = call i32 (...) @reset_colors()
%23 = call i32 @println(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 (...) @reset_colors()
%25 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%26 = call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%27 = call i32 @sgr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%28 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%29 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%30 = call i32 (...) @reset_colors()
%31 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
%32 = call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%33 = call i32 @sgr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0))
%35 = call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%36 = call i32 (...) @reset_colors()
%37 = call i32 (...) @holdit()
ret i32 0
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [74 x i8] c"ECMA-48 states that SGR 0 \22cancels the effect of any preceding occurrence\00"
@.str.2 = [77 x i8] c"of SGR in the data stream regardless of the setting of the graphic rendition\00"
@.str.3 = [26 x i8] c"combination mode (GRCM)\22.\00"
@.str.4 = [27 x i8] c"You should see only black:\00"
@.str.5 = [6 x i8] c"30;40\00"
@.str.6 = [29 x i8] c"SGR 30 and SGR 40 don't work\00"
@.str.7 = [12 x i8] c":up to here\00"
@.str.8 = [27 x i8] c"You should see only white:\00"
@.str.9 = [6 x i8] c"37;47\00"
@.str.10 = [29 x i8] c"SGR 37 and SGR 47 don't work\00"
@.str.11 = [27 x i8] c"You should see text here: \00"
@.str.12 = [2 x i8] c"0\00"
@.str.13 = [31 x i8] c"SGR 0 reset works (explicit 0)\00"
@.str.14 = [27 x i8] c"................and here: \00"
@.str.15 = [34 x i8] c"SGR 0 reset works (default param)\00"
define i32 @test_SGR_0(i8* %0) {
%2 = tail call i32 @vt_move(i32 1, i32 1)
%3 = tail call i32 @println(i8* %0)
%4 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @println(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @println(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @println(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 (...) @reset_colors()
%11 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%12 = tail call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%14 = tail call i32 (...) @reset_colors()
%15 = tail call i32 @println(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%16 = tail call i32 (...) @reset_colors()
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%18 = tail call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%19 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.10, i64 0, i64 0))
%20 = tail call i32 (...) @reset_colors()
%21 = tail call i32 @println(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%22 = tail call i32 (...) @reset_colors()
%23 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0))
%24 = tail call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%25 = tail call i32 @sgr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%26 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%27 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 (...) @reset_colors()
%29 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0))
%30 = tail call i32 @sgr(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%31 = tail call i32 @sgr(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%32 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0))
%33 = tail call i32 @println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%34 = tail call i32 (...) @reset_colors()
%35 = tail call i32 (...) @holdit()
ret i32 0
}