#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*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
void put_attr(int attr) {
  static unsigned n = 0;
  if (attr == 0) {
    if (n > 0)
      printf("\033[0m");
    n = 0;
  } else if (attr == -1) {
    if (n > 0)
      putchar('m');
  } else {
    if (n++ == 0)
      printf("\033[%d", attr);
    else
      printf(";%d", attr);
  }
}


x86 assembly (clang, -O0):
<put_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    115f <put_attr+0x3f>
cmpl   $0x0,0x2ef8(%rip)
jbe    1150 <put_attr+0x30>
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,0x2eda(%rip)
jmp    11d0 <put_attr+0xb0>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1185 <put_attr+0x65>
cmpl   $0x0,0x2ec4(%rip)
jbe    1180 <put_attr+0x60>
mov    $0x6d,%edi
call   1030 <putchar@plt>
jmp    11cb <put_attr+0xab>
mov    0x2ea9(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e9e(%rip)
cmp    $0x0,%eax
jne    11b5 <put_attr+0x95>
mov    -0x4(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c6 <put_attr+0xa6>
mov    -0x4(%rbp),%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cb <put_attr+0xab>
jmp    11d0 <put_attr+0xb0>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_attr>:
push   %rax
cmp    $0xffffffff,%edi
je     114f <put_attr+0x2f>
mov    %edi,%esi
test   %edi,%edi
jne    1165 <put_attr+0x45>
cmpl   $0x0,0x2f01(%rip)
je     1143 <put_attr+0x23>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x2ee7(%rip)
jmp    1163 <put_attr+0x43>
cmpl   $0x0,0x2ede(%rip)
je     1163 <put_attr+0x43>
mov    $0x6d,%edi
pop    %rax
jmp    1030 <putchar@plt>
pop    %rax
ret
mov    0x2ec9(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ec0(%rip)
test   %eax,%eax
je     1181 <put_attr+0x61>
lea    0xe8b(%rip),%rdi
jmp    1188 <put_attr+0x68>
lea    0xe7d(%rip),%rdi
xor    %eax,%eax
pop    %rcx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@put_attr.n = internal global i32 0
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [5 x i8] c"\1B[%d\00"
@.str.2 = [4 x i8] c";%d\00"
define void @put_attr(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* @put_attr.n
%7 = icmp ugt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %5
store i32 0, i32* @put_attr.n
br label %32
11: ; preds = %1
%12 = load i32, i32* %2
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %11
%15 = load i32, i32* @put_attr.n
%16 = icmp ugt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @putchar(i8 signext 109)
br label %19
19: ; preds = %17, %14
br label %31
20: ; preds = %11
%21 = load i32, i32* @put_attr.n
%22 = add i32 %21, 1
store i32 %22, i32* @put_attr.n
%23 = icmp eq i32 %21, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %30
27: ; preds = %20
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30, %19
br label %32
32: ; preds = %31, %10
ret void
}

LLVM IR (-O2):
@put_attr.n = internal unnamed_addr global i32 0
@.str = [5 x i8] c"\1B[0m\00"
@.str.1 = [5 x i8] c"\1B[%d\00"
@.str.2 = [4 x i8] c";%d\00"
define void @put_attr(i32 %0) {
switch i32 %0, label %13 [
i32 0, label %2
i32 -1, label %8
]
2: ; preds = %1
%3 = load i32, i32* @put_attr.n
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
store i32 0, i32* @put_attr.n
br label %21
8: ; preds = %1
%9 = load i32, i32* @put_attr.n
%10 = icmp eq i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8
%12 = tail call i32 @putchar(i8 signext 109)
br label %21
13: ; preds = %1
%14 = load i32, i32* @put_attr.n
%15 = add i32 %14, 1
store i32 %15, i32* @put_attr.n
%16 = icmp eq i32 %14, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %21
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %21
21: ; preds = %11, %8, %19, %17, %7
ret void
}