#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  char *addr;
};
typedef TYPE_1__ XrmValue;
typedef int /*<<< orphan*/ XrmDatabase;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
char *XResourceManagerString(int /*<<< orphan*/ *);
int /*<<< orphan*/ XrmGetResource(int /*<<< orphan*/, char *, char *, char **,
                                  TYPE_1__ *);
int /*<<< orphan*/ XrmGetStringDatabase(char *);
int /*<<< orphan*/ XrmInitialize();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main(int argc, char **argv) {
  Display *display;
  XrmDatabase db;
  char *resource_manager;
  XrmValue ret;
  char *var = 0;
  char *type = 0;
  if (argc < 2) {
    return -1;
  }
  XrmInitialize();
  if (!(display = XOpenDisplay(NULL))) {
    printf("Couldn't open display\n");
    return -1;
  }
  resource_manager = XResourceManagerString(display);
  if (resource_manager == NULL)
    return -2;
  db = XrmGetStringDatabase(resource_manager);
  XrmGetResource(db, argv[1], "String", &type, &ret);
  if (ret.addr != NULL && !strncmp("String", type, 64)) {
    var = ret.addr;
  } else {
    XCloseDisplay(display);
    return -1;
  }
  printf("%s\n", var);
  XCloseDisplay(display);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11bc <main+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x130>
mov    $0x0,%al
call   1050 <XrmInitialize@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f4 <main+0x74>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x130>
mov    -0x18(%rbp),%rdi
call   1090 <XResourceManagerString@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1218 <main+0x98>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12b0 <main+0x130>
mov    -0x28(%rbp),%rdi
call   1070 <XrmGetStringDatabase@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde1(%rip),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x30(%rbp),%r8
call   1040 <XrmGetResource@plt>
cmpq   $0x0,-0x30(%rbp)
je     1279 <main+0xf9>
mov    -0x40(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1279 <main+0xf9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    128e <main+0x10e>
mov    -0x18(%rbp),%rdi
call   10a0 <XCloseDisplay@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <main+0x130>
mov    -0x38(%rbp),%rsi
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <XCloseDisplay@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
mov    $0xffffffff,%ebx
cmp    $0x2,%edi
jl     123b <main+0xbb>
mov    %rsi,%r15
xor    %eax,%eax
call   1060 <XrmInitialize@plt>
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
test   %rax,%rax
je     1212 <main+0x92>
mov    %rax,%r14
mov    %rax,%rdi
call   1090 <XResourceManagerString@plt>
test   %rax,%rax
je     1220 <main+0xa0>
mov    %rax,%rdi
call   1070 <XrmGetStringDatabase@plt>
mov    0x8(%r15),%rsi
lea    0xe28(%rip),%rdx
mov    %rsp,%rcx
lea    0x8(%rsp),%r8
mov    %eax,%edi
call   1050 <XrmGetResource@plt>
cmpq   $0x0,0x8(%rsp)
je     1208 <main+0x88>
mov    (%rsp),%rsi
lea    0xe06(%rip),%rdi
mov    $0x40,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1227 <main+0xa7>
mov    %r14,%rdi
call   10a0 <XCloseDisplay@plt>
jmp    123b <main+0xbb>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
jmp    123b <main+0xbb>
mov    $0xfffffffe,%ebx
jmp    123b <main+0xbb>
mov    0x8(%rsp),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   10a0 <XCloseDisplay@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i8* }
@.str = [23 x i8] c"Couldn't open display\0A\00"
@.str.1 = [7 x i8] c"String\00"
@.str.2 = [4 x i8] c"%s\0A\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 %struct.TYPE_3__
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
store i8* null, i8** %11
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %53
15: ; preds = %2
%16 = call i32 (...) @XrmInitialize()
%17 = call i32* @XOpenDisplay(i32* null)
store i32* %17, i32** %6
%18 = icmp ne i32* %17, null
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %53
21: ; preds = %15
%22 = load i32*, i32** %6
%23 = call i8* @XResourceManagerString(i32* %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -2, i32* %3
br label %53
27: ; preds = %21
%28 = load i8*, i8** %8
%29 = call i32 @XrmGetStringDatabase(i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @XrmGetResource(i32 %30, i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %11, %struct.TYPE_3__* %9)
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %45
38: ; preds = %27
%39 = load i8*, i8** %11
%40 = call i32 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %39, i32 64)
%41 = icmp ne i32 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %38
%43 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%44 = load i8*, i8** %43
store i8* %44, i8** %10
br label %48
45: ; preds = %38, %27
%46 = load i32*, i32** %6
%47 = call i32 @XCloseDisplay(i32* %46)
store i32 -1, i32* %3
br label %53
48: ; preds = %42
%49 = load i8*, i8** %10
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %49)
%51 = load i32*, i32** %6
%52 = call i32 @XCloseDisplay(i32* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %48, %45, %26, %19, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i8* }
@.str.1 = [7 x i8] c"String\00"
@str = [22 x i8] c"Couldn't open display\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.TYPE_3__
%4 = alloca i8*
%5 = bitcast %struct.TYPE_3__* %3 to i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = icmp slt i32 %0, 2
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = tail call i32 (...) @XrmInitialize()
%10 = tail call i32* @XOpenDisplay(i32* null)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %35
14: ; preds = %8
%15 = tail call i8* @XResourceManagerString(i32* %10)
%16 = icmp eq i8* %15, null
br i1 %16, label %35, label %17
17: ; preds = %14
%18 = tail call i32 @XrmGetStringDatabase(i8* %15)
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @XrmGetResource(i32 %18, i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %4, %struct.TYPE_3__* %3)
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %3, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = icmp eq i8* %23, null
br i1 %24, label %33, label %25
25: ; preds = %17
%26 = load i8*, i8** %4
%27 = call i32 @strncmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 64)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8*, i8** %22
%31 = call i32 @puts(i8* dereferenceable(1) %30)
%32 = call i32 @XCloseDisplay(i32* %10)
br label %35
33: ; preds = %25, %17
%34 = call i32 @XCloseDisplay(i32* %10)
br label %35
35: ; preds = %14, %2, %29, %33, %12
%36 = phi i32 [ -1, %33 ], [ 0, %29 ], [ -1, %12 ], [ -1, %2 ], [ -2, %14 ]
ret i32 %36
}