#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 */
struct config_var {
  int dummy;
};

/* Variables and functions */
struct config_var *config_var_lookup(int *);
int set_config_var_struct(struct config_var *, int);
int set_config_var_ptr(int *ptr, int new_value) {
  struct config_var *var = config_var_lookup(ptr);
  if (ptr && !var) {
    *ptr = new_value;
    return 1;
  }
  return set_config_var_struct(var, new_value);
}


x86 assembly (clang, -O0):
<set_config_var_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <config_var_lookup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1167 <set_config_var_ptr+0x47>
cmpq   $0x0,-0x20(%rbp)
jne    1167 <set_config_var_ptr+0x47>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    1176 <set_config_var_ptr+0x56>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <set_config_var_struct@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_config_var_ptr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <config_var_lookup@plt>
test   %rbx,%rbx
je     1145 <set_config_var_ptr+0x25>
test   %rax,%rax
jne    1145 <set_config_var_ptr+0x25>
mov    %ebp,(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rax,%rdi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <set_config_var_struct@plt>

LLVM IR (-O0):
%struct.config_var = type { i32 }
define i32 @set_config_var_ptr(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.config_var*
store i32* %0, i32** %4
store i32 %1, i32* %5
%7 = load i32*, i32** %4
%8 = call %struct.config_var* @config_var_lookup(i32* %7)
store %struct.config_var* %8, %struct.config_var** %6
%9 = load i32*, i32** %4
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load %struct.config_var*, %struct.config_var** %6
%13 = icmp ne %struct.config_var* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32*, i32** %4
store i32 %15, i32* %16
store i32 1, i32* %3
br label %21
17: ; preds = %11, %2
%18 = load %struct.config_var*, %struct.config_var** %6
%19 = load i32, i32* %5
%20 = call i32 @set_config_var_struct(%struct.config_var* %18, i32 %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %17, %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.config_var = type { i32 }
define i32 @set_config_var_ptr(i32* %0, i32 %1) {
%3 = tail call %struct.config_var* @config_var_lookup(i32* %0)
%4 = icmp eq i32* %0, null
%5 = icmp ne %struct.config_var* %3, null
%6 = select i1 %4, i1 true, i1 %5
br i1 %6, label %8, label %7
7: ; preds = %2
store i32 %1, i32* %0
br label %10
8: ; preds = %2
%9 = tail call i32 @set_config_var_struct(%struct.config_var* %3, i32 %1)
br label %10
10: ; preds = %8, %7
%11 = phi i32 [ %9, %8 ], [ 1, %7 ]
ret i32 %11
}