#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;

/* Variables and functions */
char *DisplayString(int /*<<< orphan*/ *);
char *malloc(scalar_t__);
int /*<<< orphan*/ putenv(char *);
int /*<<< orphan*/ strcat(int /*<<< orphan*/, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
int display_env(Display *dpy) {
  const char *display_name = DisplayString(dpy);
  char *envstr = malloc(strlen(display_name) + 8 + 1);
  if (envstr != NULL) {
    strcat(strcpy(envstr, "DISPLAY="), display_name);
    putenv(envstr);
  }
}


x86 assembly (clang, -O0):
<display_env>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <DisplayString@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x8,%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c5 <display_env+0x65>
mov    -0x20(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <strcpy@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x20(%rbp),%rdi
call   1050 <putenv@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_env>:
push   %r14
push   %rbx
push   %rax
call   1080 <DisplayString@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <strlen@plt>
lea    0x9(%rax),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a6 <display_env+0x46>
mov    %rax,%rbx
lea    0xe74(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
call   1050 <putenv@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"DISPLAY=\00"
define i32 @display_env(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i8* @DisplayString(i32* %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 8
%11 = add nsw i64 %10, 1
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %22
15: ; preds = %1
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i32 %17, i8* %18)
%20 = load i8*, i8** %5
%21 = call i32 @putenv(i8* %20)
br label %22
22: ; preds = %15, %1
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [9 x i8] c"DISPLAY=\00"
define i32 @display_env(i32* %0) {
%2 = tail call i8* @DisplayString(i32* %0)
%3 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%4 = add nsw i64 %3, 9
%5 = tail call i8* @malloc(i64 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcat(i32 %8, i8* %2)
%10 = tail call i32 @putenv(i8* %5)
br label %11
11: ; preds = %7, %1
ret i32 undef
}