#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 */
int /*<<< orphan*/ free(char *);
scalar_t__ getuid();
char *test_dbus_env(char *);
int /*<<< orphan*/ test_default_socket(char *, char *, ...);
void dbus_test(void) {
  char *found_user = test_dbus_env("DBUS_SESSION_BUS_ADDRESS");
  test_default_socket(found_user, "/run/user/%d/bus", (int)getuid());
  test_default_socket(found_user, "/run/user/%d/dbus/user_bus_socket",
                      (int)getuid());
  if (found_user != NULL)
    free(found_user);
  char *found_system = test_dbus_env("DBUS_SYSTEM_BUS_ADDRESS");
  test_default_socket(found_system, "/run/dbus/system_bus_socket");
  if (found_system != NULL)
    free(found_system);
}


x86 assembly (clang, -O0):
<dbus_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1060 <test_dbus_env@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1050 <test_default_socket@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getuid@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xe93(%rip),%rsi
mov    $0x0,%al
call   1050 <test_default_socket@plt>
cmpq   $0x0,-0x8(%rbp)
je     11b2 <dbus_test+0x72>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe93(%rip),%rdi
call   1060 <test_dbus_env@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <test_default_socket@plt>
cmpq   $0x0,-0x10(%rbp)
je     11e8 <dbus_test+0xa8>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbus_test>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1060 <test_dbus_env@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <test_default_socket@plt>
xor    %eax,%eax
call   1040 <getuid@plt>
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <test_default_socket@plt>
test   %rbx,%rbx
je     1191 <dbus_test+0x51>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xeb4(%rip),%rdi
call   1060 <test_dbus_env@plt>
mov    %rax,%rbx
lea    0xebd(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1050 <test_default_socket@plt>
test   %rbx,%rbx
je     11bf <dbus_test+0x7f>
mov    %rbx,%rdi
pop    %rbx
jmp    1030 <free@plt>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [25 x i8] c"DBUS_SESSION_BUS_ADDRESS\00"
@.str.1 = [17 x i8] c"/run/user/%d/bus\00"
@.str.2 = [34 x i8] c"/run/user/%d/dbus/user_bus_socket\00"
@.str.3 = [24 x i8] c"DBUS_SYSTEM_BUS_ADDRESS\00"
@.str.4 = [28 x i8] c"/run/dbus/system_bus_socket\00"
define void @dbus_test() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i8* @test_dbus_env(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i64 (...) @getuid()
%6 = trunc i64 %5 to i32
%7 = call i32 (i8*, i8*, ...) @test_default_socket(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i8*, i8** %1
%9 = call i64 (...) @getuid()
%10 = trunc i64 %9 to i32
%11 = call i32 (i8*, i8*, ...) @test_default_socket(i8* %8, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = load i8*, i8** %1
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i8*, i8** %1
%16 = call i32 @free(i8* %15)
br label %17
17: ; preds = %14, %0
%18 = call i8* @test_dbus_env(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i8* %18, i8** %2
%19 = load i8*, i8** %2
%20 = call i32 (i8*, i8*, ...) @test_default_socket(i8* %19, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%21 = load i8*, i8** %2
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
br label %26
26: ; preds = %23, %17
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"DBUS_SESSION_BUS_ADDRESS\00"
@.str.1 = [17 x i8] c"/run/user/%d/bus\00"
@.str.2 = [34 x i8] c"/run/user/%d/dbus/user_bus_socket\00"
@.str.3 = [24 x i8] c"DBUS_SYSTEM_BUS_ADDRESS\00"
@.str.4 = [28 x i8] c"/run/dbus/system_bus_socket\00"
define void @dbus_test() {
%1 = tail call i8* @test_dbus_env(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%2 = tail call i64 (...) @getuid()
%3 = trunc i64 %2 to i32
%4 = tail call i32 (i8*, i8*, ...) @test_default_socket(i8* %1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = tail call i64 (...) @getuid()
%6 = trunc i64 %5 to i32
%7 = tail call i32 (i8*, i8*, ...) @test_default_socket(i8* %1, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = icmp eq i8* %1, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = tail call i32 @free(i8* %1)
br label %11
11: ; preds = %9, %0
%12 = tail call i8* @test_dbus_env(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 (i8*, i8*, ...) @test_default_socket(i8* %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i8* %12, null
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = tail call i32 @free(i8* %12)
br label %17
17: ; preds = %15, %11
ret void
}