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

/* Variables and functions */
char *getenv(char *);
int getmaxx();
int getmaxy();
int /*<<< orphan*/ sprintf(char *, char *, int, int, char *);
char *getmodename(int mode_number) {
  char *dpyname;
  static char modename[256];
  dpyname = getenv("DISPLAY");
  sprintf(modename, "%d x %d %s", getmaxx(), getmaxy(),
          dpyname ? dpyname : "EGAVGA");
  return modename;
}


x86 assembly (clang, -O0):
<getmodename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getmaxx@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getmaxy@plt>
mov    %eax,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1187 <getmodename+0x47>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <getmodename+0x57>
lea    0xe85(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1197 <getmodename+0x57>
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%edx
mov    -0x20(%rbp),%r8
lea    0x2ea8(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1060 <sprintf@plt>
lea    0x2e95(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getmodename>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getmaxx@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1040 <getmaxy@plt>
test   %rbx,%rbx
lea    0xea7(%rip),%r8
cmovne %rbx,%r8
lea    0x2ed9(%rip),%rbx
lea    0xe8a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <sprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@getmodename.modename = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"DISPLAY\00"
@.str.1 = [11 x i8] c"%d x %d %s\00"
@.str.2 = [7 x i8] c"EGAVGA\00"
define i8* @getmodename(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %3
%5 = call i32 (...) @getmaxx()
%6 = call i32 (...) @getmaxy()
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i8*, i8** %3
br label %12
11: ; preds = %1
br label %12
12: ; preds = %11, %9
%13 = phi i8* [ %10, %9 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %11 ]
%14 = call i32 @sprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @getmodename.modename, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %6, i8* %13)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @getmodename.modename, i64 0, i64 0)
}

LLVM IR (-O2):
@getmodename.modename = internal global [256 x i8] zeroinitializer
@.str = [8 x i8] c"DISPLAY\00"
@.str.1 = [11 x i8] c"%d x %d %s\00"
@.str.2 = [7 x i8] c"EGAVGA\00"
define i8* @getmodename(i32 %0) {
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @getmaxx()
%4 = tail call i32 (...) @getmaxy()
%5 = icmp eq i8* %2, null
%6 = select i1 %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2
%7 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([256 x i8], [256 x i8]* @getmodename.modename, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %4, i8* %6)
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @getmodename.modename, i64 0, i64 0)
}