#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*/ Display;
typedef int /*<<< orphan*/ Bool;

/* Variables and functions */
int /*<<< orphan*/ XNVCTRLQueryStringAttribute(int /*<<< orphan*/ *, int,
                                               int /*<<< orphan*/, int,
                                               char **);
int /*<<< orphan*/ XNVCTRLSetStringAttribute(int /*<<< orphan*/ *, int,
                                             int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strdup(char *);
int strlen(char const *);
char *strstr(char *, char const *);
int RemoveAttributeFromDisplayOfCurrentMetaMode(Display *xDpy, int screenId,
                                                int nvDpyId,
                                                const char *attribute) {
  char *pOldCurrentMetaMode = NULL;
  char *pCurrentMetaMode = NULL;
  char displayName[512];
  char *pDisplay;
  char *pNextDisplay;
  char *pAttributeList;
  char *pTargetAttribute;
  char *newMetaMode = NULL;
  int error = 1;
  int attributeLen;
  Bool ret;
  if (!attribute) {
    goto cleanup;
  }
  attributeLen = strlen(attribute);
  ret =
      XNVCTRLQueryStringAttribute(xDpy, screenId, 0, 45, &pOldCurrentMetaMode);
  if (!ret || !pOldCurrentMetaMode) {
    goto cleanup;
  }
  pCurrentMetaMode = strstr(pOldCurrentMetaMode, "::");
  pCurrentMetaMode += 2;
  newMetaMode = strdup(pCurrentMetaMode);
  if (!newMetaMode) {
    goto cleanup;
  }
  sprintf(displayName, "DPY-%i", nvDpyId);
  pDisplay = strstr(pCurrentMetaMode, displayName);
  if (!pDisplay) {
    goto cleanup;
  }
  pNextDisplay = strstr(pDisplay + 1, "DPY-");
  if (pNextDisplay) {
    *pNextDisplay = '\0';
  }
  if (!(pAttributeList = strstr(pDisplay, "{"))) {
    goto cleanup;
  }
  pTargetAttribute = strstr(pAttributeList, attribute);
  if (!pTargetAttribute) {
    goto cleanup;
  }
  while (attributeLen--) {
    newMetaMode[pTargetAttribute - pCurrentMetaMode + attributeLen] = 'z';
  }
  XNVCTRLSetStringAttribute(xDpy, screenId, 0, 45, newMetaMode);
  XSync(xDpy, 0);
  error = 0;
cleanup:
  if (newMetaMode) {
    free(newMetaMode);
  }
  if (pOldCurrentMetaMode) {
    free(pOldCurrentMetaMode);
  }
  return error;
}


x86 assembly (clang, -O0):
<RemoveAttributeFromDisplayOfCurrentMetaMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x258(%rbp)
movl   $0x1,-0x25c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <RemoveAttributeFromDisplayOfCurrentMetaMode+0x4e>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x260(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
mov    $0x2d,%ecx
lea    -0x20(%rbp),%r8
call   1040 <XNVCTRLQueryStringAttribute@plt>
mov    %eax,-0x264(%rbp)
cmpl   $0x0,-0x264(%rbp)
je     1212 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x92>
cmpq   $0x0,-0x20(%rbp)
jne    1217 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x97>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
mov    -0x20(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <strdup@plt>
mov    %rax,-0x258(%rbp)
cmpq   $0x0,-0x258(%rbp)
jne    125a <RemoveAttributeFromDisplayOfCurrentMetaMode+0xda>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
lea    -0x230(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    0xd98(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x230(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    129a <RemoveAttributeFromDisplayOfCurrentMetaMode+0x11a>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
mov    -0x238(%rbp),%rdi
add    $0x1,%rdi
lea    0xd5e(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x240(%rbp)
cmpq   $0x0,-0x240(%rbp)
je     12d0 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x150>
mov    -0x240(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x238(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x248(%rbp)
cmp    $0x0,%rax
jne    12f9 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x179>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
mov    -0x248(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
mov    %rax,-0x250(%rbp)
cmpq   $0x0,-0x250(%rbp)
jne    1323 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x1a3>
jmp    1399 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x219>
jmp    1328 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x1a8>
mov    -0x260(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x260(%rbp)
cmp    $0x0,%eax
je     136a <RemoveAttributeFromDisplayOfCurrentMetaMode+0x1ea>
mov    -0x258(%rbp),%rax
mov    -0x250(%rbp),%rcx
mov    -0x28(%rbp),%rdx
sub    %rdx,%rcx
movslq -0x260(%rbp),%rdx
add    %rdx,%rcx
movb   $0x7a,(%rax,%rcx,1)
jmp    1328 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x1a8>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x258(%rbp),%r8
xor    %edx,%edx
mov    $0x2d,%ecx
call   1060 <XNVCTRLSetStringAttribute@plt>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1070 <XSync@plt>
movl   $0x0,-0x25c(%rbp)
cmpq   $0x0,-0x258(%rbp)
je     13b3 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x233>
mov    -0x258(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     13c7 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x247>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x25c(%rbp),%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RemoveAttributeFromDisplayOfCurrentMetaMode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
movq   $0x0,0x10(%rsp)
test   %rcx,%rcx
je     130c <RemoveAttributeFromDisplayOfCurrentMetaMode+0x16c>
mov    %rcx,%r15
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1050 <strlen@plt>
mov    %rax,0x28(%rsp)
lea    0x10(%rsp),%r8
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    $0x2d,%ecx
call   1040 <XNVCTRLQueryStringAttribute@plt>
mov    0x10(%rsp),%r12
mov    $0x1,%r13d
test   %eax,%eax
je     132e <RemoveAttributeFromDisplayOfCurrentMetaMode+0x18e>
test   %r12,%r12
je     132e <RemoveAttributeFromDisplayOfCurrentMetaMode+0x18e>
mov    %ebp,0x1c(%rsp)
mov    %rbx,0x20(%rsp)
lea    0xde3(%rip),%rsi
mov    %r12,%rdi
call   10c0 <strstr@plt>
mov    %rax,%rbp
add    $0x2,%rbp
mov    %rbp,%rdi
call   10b0 <strdup@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1314 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x174>
lea    0xdba(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14d,%edx
call   10a0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10c0 <strstr@plt>
mov    $0x1,%r13d
test   %rax,%rax
je     131c <RemoveAttributeFromDisplayOfCurrentMetaMode+0x17c>
mov    %rax,%r14
mov    %rax,%rdi
add    $0x1,%rdi
lea    0xd86(%rip),%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1291 <RemoveAttributeFromDisplayOfCurrentMetaMode+0xf1>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x7b,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     131c <RemoveAttributeFromDisplayOfCurrentMetaMode+0x17c>
mov    %rax,%rdi
mov    %r15,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
mov    0x8(%rsp),%rbx
je     1321 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x181>
mov    0x28(%rsp),%rsi
test   %esi,%esi
je     12e2 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x142>
lea    -0x1(%rsi),%ecx
movslq %ecx,%rdx
add    %rdx,%rax
add    %rcx,%rbp
sub    %rbp,%rax
mov    %rbx,%rdi
add    %rax,%rdi
mov    %esi,%edx
mov    $0x7a,%esi
call   1070 <memset@plt>
xor    %r13d,%r13d
mov    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    0x1c(%rsp),%esi
xor    %edx,%edx
mov    $0x2d,%ecx
mov    %rbx,%r8
call   1080 <XNVCTRLSetStringAttribute@plt>
mov    %rbp,%rdi
xor    %esi,%esi
call   1090 <XSync@plt>
jmp    1321 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x181>
mov    $0x1,%r13d
jmp    133b <RemoveAttributeFromDisplayOfCurrentMetaMode+0x19b>
mov    $0x1,%r13d
jmp    1333 <RemoveAttributeFromDisplayOfCurrentMetaMode+0x193>
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%r12
test   %r12,%r12
je     133b <RemoveAttributeFromDisplayOfCurrentMetaMode+0x19b>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13d,%eax
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"::\00"
@.str.1 = [7 x i8] c"DPY-%i\00"
@.str.2 = [5 x i8] c"DPY-\00"
@.str.3 = [2 x i8] c"{\00"
define i32 @RemoveAttributeFromDisplayOfCurrentMetaMode(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [512 x i8]
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i8* null, i8** %9
store i8* null, i8** %10
store i8* null, i8** %16
store i32 1, i32* %17
%20 = load i8*, i8** %8
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %4
br label %98
23: ; preds = %4
%24 = load i8*, i8** %8
%25 = call i32 @strlen(i8* %24)
store i32 %25, i32* %18
%26 = load i32*, i32** %5
%27 = load i32, i32* %6
%28 = call i32 @XNVCTRLQueryStringAttribute(i32* %26, i32 %27, i32 0, i32 45, i8** %9)
store i32 %28, i32* %19
%29 = load i32, i32* %19
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load i8*, i8** %9
%33 = icmp ne i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31, %23
br label %98
35: ; preds = %31
%36 = load i8*, i8** %9
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %37, i8** %10
%38 = load i8*, i8** %10
%39 = getelementptr inbounds i8, i8* %38, i64 2
store i8* %39, i8** %10
%40 = load i8*, i8** %10
%41 = call i8* @strdup(i8* %40)
store i8* %41, i8** %16
%42 = load i8*, i8** %16
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %35
br label %98
45: ; preds = %35
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%47 = load i32, i32* %7
%48 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i8*, i8** %10
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %11, i64 0, i64 0
%51 = call i8* @strstr(i8* %49, i8* %50)
store i8* %51, i8** %12
%52 = load i8*, i8** %12
%53 = icmp ne i8* %52, null
br i1 %53, label %55, label %54
54: ; preds = %45
br label %98
55: ; preds = %45
%56 = load i8*, i8** %12
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = call i8* @strstr(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i8* %58, i8** %13
%59 = load i8*, i8** %13
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = load i8*, i8** %13
store i8 0, i8* %62
br label %63
63: ; preds = %61, %55
%64 = load i8*, i8** %12
%65 = call i8* @strstr(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %65, i8** %14
%66 = icmp ne i8* %65, null
br i1 %66, label %68, label %67
67: ; preds = %63
br label %98
68: ; preds = %63
%69 = load i8*, i8** %14
%70 = load i8*, i8** %8
%71 = call i8* @strstr(i8* %69, i8* %70)
store i8* %71, i8** %15
%72 = load i8*, i8** %15
%73 = icmp ne i8* %72, null
br i1 %73, label %75, label %74
74: ; preds = %68
br label %98
75: ; preds = %68
br label %76
76: ; preds = %80, %75
%77 = load i32, i32* %18
%78 = add nsw i32 %77, -1
store i32 %78, i32* %18
%79 = icmp ne i32 %77, 0
br i1 %79, label %80, label %91
80: ; preds = %76
%81 = load i8*, i8** %16
%82 = load i8*, i8** %15
%83 = load i8*, i8** %10
%84 = ptrtoint i8* %82 to i64
%85 = ptrtoint i8* %83 to i64
%86 = sub i64 %84, %85
%87 = load i32, i32* %18
%88 = sext i32 %87 to i64
%89 = add nsw i64 %86, %88
%90 = getelementptr inbounds i8, i8* %81, i64 %89
store i8 122, i8* %90
br label %76
91: ; preds = %76
%92 = load i32*, i32** %5
%93 = load i32, i32* %6
%94 = load i8*, i8** %16
%95 = call i32 @XNVCTRLSetStringAttribute(i32* %92, i32 %93, i32 0, i32 45, i8* %94)
%96 = load i32*, i32** %5
%97 = call i32 @XSync(i32* %96, i32 0)
store i32 0, i32* %17
br label %98
98: ; preds = %91, %74, %67, %54, %44, %34, %22
%99 = load i8*, i8** %16
%100 = icmp ne i8* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i8*, i8** %16
%103 = call i32 @free(i8* %102)
br label %104
104: ; preds = %101, %98
%105 = load i8*, i8** %9
%106 = icmp ne i8* %105, null
br i1 %106, label %107, label %110
107: ; preds = %104
%108 = load i8*, i8** %9
%109 = call i32 @free(i8* %108)
br label %110
110: ; preds = %107, %104
%111 = load i32, i32* %17
ret i32 %111
}

LLVM IR (-O2):
@.str = [3 x i8] c"::\00"
@.str.1 = [7 x i8] c"DPY-%i\00"
@.str.2 = [5 x i8] c"DPY-\00"
define i32 @RemoveAttributeFromDisplayOfCurrentMetaMode(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca [512 x i8]
%7 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%9 = icmp eq i8* %3, null
br i1 %9, label %65, label %10
10: ; preds = %4
%11 = tail call i32 @strlen(i8* %3)
%12 = call i32 @XNVCTRLQueryStringAttribute(i32* %0, i32 %1, i32 0, i32 45, i8** %5)
%13 = icmp ne i32 %12, 0
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
%16 = select i1 %13, i1 %15, i1 false
br i1 %16, label %17, label %57
17: ; preds = %10
%18 = call i8* @strstr(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %18, i64 2
%20 = call i8* @strdup(i8* %19)
%21 = icmp eq i8* %20, null
br i1 %21, label %61, label %22
22: ; preds = %17
%23 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%24 = call i8* @strstr(i8* %19, i8* %8)
%25 = icmp eq i8* %24, null
br i1 %25, label %53, label %26
26: ; preds = %22
%27 = getelementptr inbounds i8, i8* %24, i64 1
%28 = call i8* @strstr(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %26
store i8 0, i8* %28
br label %31
31: ; preds = %30, %26
%32 = call i8* @strchr(i8* %24, i32 123)
%33 = icmp eq i8* %32, null
br i1 %33, label %53, label %34
34: ; preds = %31
%35 = call i8* @strstr(i8* %32, i8* %3)
%36 = icmp eq i8* %35, null
br i1 %36, label %53, label %37
37: ; preds = %34
%38 = icmp eq i32 %11, 0
br i1 %38, label %50, label %39
39: ; preds = %37
%40 = ptrtoint i8* %35 to i64
%41 = ptrtoint i8* %19 to i64
%42 = add i32 %11, -1
%43 = sext i32 %42 to i64
%44 = add i64 %40, %43
%45 = zext i32 %42 to i64
%46 = add i64 %41, %45
%47 = sub i64 %44, %46
%48 = getelementptr i8, i8* %20, i64 %47
%49 = zext i32 %11 to i64
br label %50
50: ; preds = %39, %37
%51 = call i32 @XNVCTRLSetStringAttribute(i32* %0, i32 %1, i32 0, i32 45, i8* %20)
%52 = call i32 @XSync(i32* %0, i32 0)
br label %53
53: ; preds = %50, %34, %31, %22
%54 = phi i32 [ 1, %22 ], [ 1, %31 ], [ 1, %34 ], [ 0, %50 ]
%55 = call i32 @free(i8* %20)
%56 = load i8*, i8** %5
br label %57
57: ; preds = %53, %10
%58 = phi i8* [ %14, %10 ], [ %56, %53 ]
%59 = phi i32 [ 1, %10 ], [ %54, %53 ]
%60 = icmp eq i8* %58, null
br i1 %60, label %65, label %61
61: ; preds = %17, %57
%62 = phi i32 [ %59, %57 ], [ 1, %17 ]
%63 = phi i8* [ %58, %57 ], [ %14, %17 ]
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %4, %61, %57
%66 = phi i32 [ %62, %61 ], [ %59, %57 ], [ 1, %4 ]
ret i32 %66
}