#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*/ tbuf;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ realpath(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int write(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  int i, perm = 0;
  if (!getenv("TERMINOLOGY"))
    return 0;
  if (argc <= 1) {
    printf("Usage: %s [-p] FILE1 [FILE2 ...]\n"
           "  Change the terminal background to the given file/uri\n"
           "  -p  Make change permanent (stored in config)\n"
           "\n",
           argv[0]);
    return 0;
  }
  for (i = 1; i < argc; i++) {
    char *path, buf[PATH_MAX * 2], tbuf[PATH_MAX * 3];
    if (!strcmp(argv[i], "-p")) {
      perm = 1;
      i++;
      if (i >= argc)
        break;
    }
    path = argv[i];
    if (realpath(path, buf))
      path = buf;
    if (perm)
      snprintf(tbuf, sizeof(tbuf), "%c}bp%s", 0x1b, path);
    else
      snprintf(tbuf, sizeof(tbuf), "%c}bt%s", 0x1b, path);
    if (write(0, tbuf, strlen(tbuf)) < 1)
      perror("write");
    tbuf[0] = 0;
    if (write(0, tbuf, 1) < 1)
      perror("write");
  }
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe4c(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%eax
jne    11ce <main+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    13b9 <main+0x229>
cmpl   $0x1,-0x8(%rbp)
jg     11f7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe26(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b9 <main+0x229>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    13b2 <main+0x222>
mov    0x2ddf(%rip),%rax
mov    (%rax),%ecx
add    %ecx,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x58(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %rax,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe23(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    12ad <main+0x11d>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jl     12a8 <main+0x118>
movl   $0x2,-0x3c(%rbp)
jmp    1383 <main+0x1f3>
jmp    12ad <main+0x11d>
mov    -0x58(%rbp),%rsi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1090 <realpath@plt>
cmp    $0x0,%rax
je     12dc <main+0x14c>
mov    -0x58(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     130a <main+0x17a>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%r8
lea    0xd9d(%rip),%rdx
mov    $0x1b,%ecx
call   1070 <snprintf@plt>
jmp    1329 <main+0x199>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
mov    -0x20(%rbp),%r8
lea    0xd81(%rip),%rdx
mov    $0x1b,%ecx
call   1070 <snprintf@plt>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rsi
mov    %eax,%edx
xor    %edi,%edi
call   1040 <write@plt>
cmp    $0x1,%eax
jge    1354 <main+0x1c4>
lea    0xd59(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x48(%rbp),%rsi
movb   $0x0,(%rsi)
xor    %edi,%edi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
jge    137c <main+0x1ec>
lea    0xd31(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x3c(%rbp),%eax
test   %eax,%eax
je     139f <main+0x20f>
jmp    139a <main+0x20a>
jmp    13b2 <main+0x222>
jmp    13a4 <main+0x214>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11fe <main+0x6e>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %edi,%ebx
lea    0xe53(%rip),%rdi
call   1030 <getenv@plt>
test   %eax,%eax
je     11ca <main+0x3a>
cmp    $0x2,%ebx
jge    11db <main+0x4b>
mov    (%r14),%rsi
lea    0xe47(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x1,%r13d
mov    %r14,-0x38(%rbp)
jmp    1211 <main+0x81>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rsp
add    $0x1,%r13d
cmp    -0x2c(%rbp),%r13d
jge    1325 <main+0x195>
mov    %rsp,%r15
mov    0x2dd5(%rip),%rcx
mov    (%rcx),%eax
add    %eax,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    (%rcx),%eax
lea    (%rax,%rax,2),%eax
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
movslq %r13d,%rax
mov    (%r14,%rax,8),%r14
mov    %r14,%rdi
lea    0xe3a(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
mov    %r15,-0x40(%rbp)
je     126e <main+0xde>
mov    -0x30(%rbp),%r15d
jmp    128d <main+0xfd>
add    $0x1,%r13d
cmp    -0x2c(%rbp),%r13d
jge    132c <main+0x19c>
movslq %r13d,%rax
mov    -0x38(%rbp),%rcx
mov    (%rcx,%rax,8),%r14
mov    $0x1,%r15d
mov    %r14,%rdi
mov    %r12,%rsi
call   1090 <realpath@plt>
test   %rax,%rax
cmove  %r14,%r12
mov    %r15d,-0x30(%rbp)
test   %r15d,%r15d
lea    0xdeb(%rip),%rdx
lea    0xdec(%rip),%rax
cmove  %rax,%rdx
mov    %rbx,%rdi
mov    -0x48(%rbp),%rsi
mov    $0x1b,%ecx
mov    %r12,%r8
call   1070 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
jle    1317 <main+0x187>
movb   $0x0,(%rbx)
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
test   %eax,%eax
mov    -0x38(%rbp),%r14
mov    -0x40(%rbp),%rbx
jg     1200 <main+0x70>
lea    0xd9b(%rip),%rdi
call   10a0 <perror@plt>
jmp    1200 <main+0x70>
lea    0xd8a(%rip),%rdi
call   10a0 <perror@plt>
jmp    12e4 <main+0x154>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rsp
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"TERMINOLOGY\00"
@.str.1 = [137 x i8] c"Usage: %s [-p] FILE1 [FILE2 ...]\0A Change the terminal background to the given file/uri\0A -p Make change permanent (stored in config)\0A\0A\00"
@PATH_MAX = global i32 0
@.str.2 = [3 x i8] c"-p\00"
@.str.3 = [8 x i8] c"%c}bp%s\00"
@.str.4 = [8 x i8] c"%c}bt%s\00"
@.str.5 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%13 = call i32 @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 0, i32* %3
br label %97
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sle i32 %17, 1
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i8* %22)
store i32 0, i32* %3
br label %97
24: ; preds = %16
store i32 1, i32* %6
br label %25
25: ; preds = %92, %24
%26 = load i32, i32* %6
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %95
29: ; preds = %25
%30 = load i32, i32* @PATH_MAX
%31 = mul nsw i32 %30, 2
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %9
%34 = alloca i8, i64 %32
store i64 %32, i64* %10
%35 = load i32, i32* @PATH_MAX
%36 = mul nsw i32 %35, 3
%37 = zext i32 %36 to i64
%38 = alloca i8, i64 %37
store i64 %37, i64* %11
%39 = load i8**, i8*** %5
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %54, label %46
46: ; preds = %29
store i32 1, i32* %7
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = load i32, i32* %4
%51 = icmp sge i32 %49, %50
br i1 %51, label %52, label %53
52: ; preds = %46
store i32 2, i32* %12
br label %88
53: ; preds = %46
br label %54
54: ; preds = %53, %29
%55 = load i8**, i8*** %5
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
store i8* %59, i8** %8
%60 = load i8*, i8** %8
%61 = call i64 @realpath(i8* %60, i8* %34)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %64
63: ; preds = %54
store i8* %34, i8** %8
br label %64
64: ; preds = %63, %54
%65 = load i32, i32* %7
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %64
%68 = trunc i64 %37 to i32
%69 = load i8*, i8** %8
%70 = call i32 @snprintf(i8* %38, i32 %68, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 27, i8* %69)
br label %75
71: ; preds = %64
%72 = trunc i64 %37 to i32
%73 = load i8*, i8** %8
%74 = call i32 @snprintf(i8* %38, i32 %72, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 27, i8* %73)
br label %75
75: ; preds = %71, %67
%76 = call i32 @strlen(i8* %38)
%77 = call i32 @write(i32 0, i8* %38, i32 %76)
%78 = icmp slt i32 %77, 1
br i1 %78, label %79, label %81
79: ; preds = %75
%80 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %81
81: ; preds = %79, %75
%82 = getelementptr inbounds i8, i8* %38, i64 0
store i8 0, i8* %82
%83 = call i32 @write(i32 0, i8* %38, i32 1)
%84 = icmp slt i32 %83, 1
br i1 %84, label %85, label %87
85: ; preds = %81
%86 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %81
store i32 0, i32* %12
br label %88
88: ; preds = %87, %52
%89 = load i8*, i8** %9
%90 = load i32, i32* %12
switch i32 %90, label %99 [
i32 0, label %91
i32 2, label %95
]
91: ; preds = %88
br label %92
92: ; preds = %91
%93 = load i32, i32* %6
%94 = add nsw i32 %93, 1
store i32 %94, i32* %6
br label %25
95: ; preds = %88, %25
%96 = call i32 @exit(i32 0)
unreachable
97: ; preds = %19, %15
%98 = load i32, i32* %3
ret i32 %98
99: ; preds = %88
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"TERMINOLOGY\00"
@.str.1 = [137 x i8] c"Usage: %s [-p] FILE1 [FILE2 ...]\0A Change the terminal background to the given file/uri\0A -p Make change permanent (stored in config)\0A\0A\00"
@PATH_MAX = global i32 0
@.str.2 = [3 x i8] c"-p\00"
@.str.3 = [8 x i8] c"%c}bp%s\00"
@.str.4 = [8 x i8] c"%c}bt%s\00"
@.str.5 = [6 x i8] c"write\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %60, label %5
5: ; preds = %2
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %5
%8 = load i8*, i8** %1
%9 = tail call i32 @printf(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.1, i64 0, i64 0), i8* %8)
br label %60
10: ; preds = %5, %55
%11 = phi i32 [ %56, %55 ], [ 1, %5 ]
%12 = phi i32 [ %36, %55 ], [ 0, %5 ]
%13 = load i32, i32* @PATH_MAX
%14 = shl nsw i32 %13, 1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = load i32, i32* @PATH_MAX
%19 = mul nsw i32 %18, 3
%20 = zext i32 %19 to i64
%21 = alloca i8, i64 %20
%22 = sext i32 %11 to i64
%23 = getelementptr inbounds i8*, i8** %1, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @strcmp(i8* dereferenceable(1) %24, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %34
27: ; preds = %10
%28 = add nsw i32 %11, 1
%29 = icmp slt i32 %28, %0
br i1 %29, label %30, label %54
30: ; preds = %27
%31 = sext i32 %28 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
br label %34
34: ; preds = %30, %10
%35 = phi i8* [ %24, %10 ], [ %33, %30 ]
%36 = phi i32 [ %12, %10 ], [ 1, %30 ]
%37 = phi i32 [ %11, %10 ], [ %28, %30 ]
%38 = call i64 @realpath(i8* %35, i8* %17)
%39 = icmp eq i64 %38, 0
%40 = select i1 %39, i8* %35, i8* %17
%41 = icmp eq i32 %36, 0
%42 = select i1 %41, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0)
%43 = call i32 @snprintf(i8* %21, i32 %19, i8* %42, i32 27, i8* %40)
%44 = call i32 @strlen(i8* %21)
%45 = call i32 @write(i32 0, i8* %21, i32 %44)
%46 = icmp slt i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %34
%48 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %49
49: ; preds = %47, %34
store i8 0, i8* %21
%50 = call i32 @write(i32 0, i8* %21, i32 1)
%51 = icmp slt i32 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
br label %55
54: ; preds = %27
br label %58
55: ; preds = %52, %49
%56 = add nsw i32 %37, 1
%57 = icmp slt i32 %56, %0
br i1 %57, label %10, label %58
58: ; preds = %55, %54
%59 = call i32 @exit(i32 0)
unreachable
60: ; preds = %2, %7
ret i32 0
}