#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 */
int DisplayHeight(int /*<<< orphan*/ *, int);
int DisplayHeightMM(int /*<<< orphan*/ *, int);
int DisplayWidth(int /*<<< orphan*/ *, int);
int DisplayWidthMM(int /*<<< orphan*/ *, int);
int EXIT_SUCCESS;
int ScreenCount(int /*<<< orphan*/ *);
char *XDisplayName(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  Display *dpy = XOpenDisplay(NULL);
  if (!dpy) {
    fprintf(stderr, "xdpi:  unable to open default display \"%s\".\n",
            XDisplayName(NULL));
    exit(1);
  }
  for (int scr = 0; scr < ScreenCount(dpy); ++scr) {
    int w = DisplayWidth(dpy, scr);
    int h = DisplayHeight(dpy, scr);
    int mw = DisplayWidthMM(dpy, scr);
    int mh = DisplayHeightMM(dpy, scr);
    int xdpi = 0.5 + 25.4 * w / mw;
    int ydpi = 0.5 + 25.4 * h / mh;
    printf("xdpi=%d ydpi=%d\n", xdpi, ydpi);
  }
  return EXIT_SUCCESS;
}


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)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ff <main+0x5f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <XDisplayName@plt>
mov    -0x38(%rbp),%edi
mov    %rax,%rdx
lea    0xe20(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <ScreenCount@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jge    12d8 <main+0x138>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <DisplayWidth@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <DisplayHeight@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1030 <DisplayWidthMM@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   10a0 <DisplayHeightMM@plt>
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xd9d(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsi2sdl -0x28(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd80(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xd70(%rip),%xmm1
mulsd  %xmm0,%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xd53(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xd78(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1206 <main+0x66>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %edi,%edi
call   1080 <XOpenDisplay@plt>
test   %rax,%rax
je     1291 <main+0xf1>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <ScreenCount@plt>
test   %eax,%eax
jle    1279 <main+0xd9>
xor    %ebp,%ebp
lea    0xe66(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <DisplayWidth@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <DisplayHeight@plt>
mov    %eax,%r12d
mov    %r13,%rdi
mov    %ebp,%esi
call   1030 <DisplayWidthMM@plt>
mov    %eax,%ebx
mov    %r13,%rdi
mov    %ebp,%esi
call   10a0 <DisplayHeightMM@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  0xde0(%rip),%xmm2
mulsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
movsd  0xdd1(%rip),%xmm3
addsd  %xmm3,%xmm0
cvttsd2si %xmm0,%esi
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
mulsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
addsd  %xmm3,%xmm0
cvttsd2si %xmm0,%edx
mov    %r14,%rdi
call   1060 <printf@plt>
add    $0x1,%ebp
mov    %r13,%rdi
call   1070 <ScreenCount@plt>
cmp    %eax,%ebp
jl     11e0 <main+0x40>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d48(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
call   10b0 <XDisplayName@plt>
lea    0xd68(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"xdpi: unable to open default display \22%s\22.\0A\00"
@.str.1 = [17 x i8] c"xdpi=%d ydpi=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = call i32* @XOpenDisplay(i32* null)
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp ne i32* %15, null
br i1 %16, label %22, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i8* @XDisplayName(i32* null)
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
store i32 0, i32* %7
br label %23
23: ; preds = %60, %22
%24 = load i32, i32* %7
%25 = load i32*, i32** %6
%26 = call i32 @ScreenCount(i32* %25)
%27 = icmp slt i32 %24, %26
br i1 %27, label %28, label %63
28: ; preds = %23
%29 = load i32*, i32** %6
%30 = load i32, i32* %7
%31 = call i32 @DisplayWidth(i32* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32*, i32** %6
%33 = load i32, i32* %7
%34 = call i32 @DisplayHeight(i32* %32, i32 %33)
store i32 %34, i32* %9
%35 = load i32*, i32** %6
%36 = load i32, i32* %7
%37 = call i32 @DisplayWidthMM(i32* %35, i32 %36)
store i32 %37, i32* %10
%38 = load i32*, i32** %6
%39 = load i32, i32* %7
%40 = call i32 @DisplayHeightMM(i32* %38, i32 %39)
store i32 %40, i32* %11
%41 = load i32, i32* %8
%42 = sitofp i32 %41 to double
%43 = fmul double 2.540000e+01, %42
%44 = load i32, i32* %10
%45 = sitofp i32 %44 to double
%46 = fdiv double %43, %45
%47 = fadd double 5.000000e-01, %46
%48 = fptosi double %47 to i32
store i32 %48, i32* %12
%49 = load i32, i32* %9
%50 = sitofp i32 %49 to double
%51 = fmul double 2.540000e+01, %50
%52 = load i32, i32* %11
%53 = sitofp i32 %52 to double
%54 = fdiv double %51, %53
%55 = fadd double 5.000000e-01, %54
%56 = fptosi double %55 to i32
store i32 %56, i32* %13
%57 = load i32, i32* %12
%58 = load i32, i32* %13
%59 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %57, i32 %58)
br label %60
60: ; preds = %28
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %23
63: ; preds = %23
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"xdpi: unable to open default display \22%s\22.\0A\00"
@.str.1 = [17 x i8] c"xdpi=%d ydpi=%d\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @XOpenDisplay(i32* null)
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @ScreenCount(i32* %3)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %15, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i8* @XDisplayName(i32* null)
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %15, %5
%14 = load i32, i32* @EXIT_SUCCESS
ret i32 %14
15: ; preds = %5, %15
%16 = phi i32 [ %34, %15 ], [ 0, %5 ]
%17 = tail call i32 @DisplayWidth(i32* %3, i32 %16)
%18 = tail call i32 @DisplayHeight(i32* %3, i32 %16)
%19 = tail call i32 @DisplayWidthMM(i32* %3, i32 %16)
%20 = tail call i32 @DisplayHeightMM(i32* %3, i32 %16)
%21 = sitofp i32 %17 to double
%22 = fmul double %21, 2.540000e+01
%23 = sitofp i32 %19 to double
%24 = fdiv double %22, %23
%25 = fadd double %24, 5.000000e-01
%26 = fptosi double %25 to i32
%27 = sitofp i32 %18 to double
%28 = fmul double %27, 2.540000e+01
%29 = sitofp i32 %20 to double
%30 = fdiv double %28, %29
%31 = fadd double %30, 5.000000e-01
%32 = fptosi double %31 to i32
%33 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %32)
%34 = add nuw nsw i32 %16, 1
%35 = tail call i32 @ScreenCount(i32* %3)
%36 = icmp slt i32 %34, %35
br i1 %36, label %15, label %13
}