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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int sscanf(char *, char *, char *);
char *strsep(char **, char *);
char *get_x11i() {
  FILE *f;
  char buf[256], *s, *t;
  static char x11i[64] = {};
  if (*x11i)
    return x11i;
  if ((f = fopen("/proc/cmdline", "r"))) {
    if (fgets(buf, sizeof buf, f)) {
      t = buf;
      while ((s = strsep(&t, " "))) {
        if (sscanf(s, "x11i=%60s", x11i) == 1)
          break;
      }
    }
    fclose(f);
  }
  return x11i;
}


x86 assembly (clang, -O0):
<get_x11i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
cmpb   $0x0,0x2efe(%rip)
je     1178 <get_x11i+0x28>
lea    0x2ef1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1230 <get_x11i+0xe0>
lea    0xe81(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1225 <get_x11i+0xd5>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     121c <get_x11i+0xcc>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x120(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <strsep@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     1217 <get_x11i+0xc7>
mov    -0x118(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    0x2e61(%rip),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    1212 <get_x11i+0xc2>
jmp    1217 <get_x11i+0xc7>
jmp    11c6 <get_x11i+0x76>
jmp    121c <get_x11i+0xcc>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0x2e34(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_x11i>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x110,%rsp
cmpb   $0x0,0x2ef9(%rip)
jne    11fb <get_x11i+0xab>
lea    0xe8c(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fb <get_x11i+0xab>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f3 <get_x11i+0xa3>
mov    %rbx,0x8(%rsp)
lea    0xe62(%rip),%r15
lea    0x8(%rsp),%r13
lea    0xe58(%rip),%r12
lea    0x2e9f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1050 <strsep@plt>
test   %rax,%rax
je     11f3 <get_x11i+0xa3>
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11d0 <get_x11i+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    0x2e5e(%rip),%rax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@get_x11i.x11i = internal global [64 x i8] zeroinitializer
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [10 x i8] c"x11i=%60s\00"
define i8* @get_x11i() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = load i8, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0)
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0), i8** %1
br label %33
9: ; preds = %0
%10 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %32
12: ; preds = %9
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = load i32*, i32** %2
%15 = call i64 @fgets(i8* %13, i32 256, i32* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %29
17: ; preds = %12
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
store i8* %18, i8** %5
br label %19
19: ; preds = %27, %17
%20 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %20, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @sscanf(i8* %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0))
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %22
br label %28
27: ; preds = %22
br label %19
28: ; preds = %26, %19
br label %29
29: ; preds = %28, %12
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29, %9
store i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0), i8** %1
br label %33
33: ; preds = %32, %8
%34 = load i8*, i8** %1
ret i8* %34
}

LLVM IR (-O2):
@get_x11i.x11i = internal global [64 x i8] zeroinitializer
@.str = [14 x i8] c"/proc/cmdline\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [10 x i8] c"x11i=%60s\00"
define i8* @get_x11i() {
%1 = alloca [256 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
%5 = load i8, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0)
%6 = icmp eq i8 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %0
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = call i64 @fgets(i8* %3, i32 256, i32* %8)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %10
store i8* %3, i8** %2
br label %14
14: ; preds = %17, %13
%15 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0))
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %14
20: ; preds = %14, %17, %10
%21 = call i32 @fclose(i32* %8)
br label %22
22: ; preds = %7, %20, %0
ret i8* getelementptr inbounds ([64 x i8], [64 x i8]* @get_x11i.x11i, i64 0, i64 0)
}