#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 sd_sys {
  int dummy;
};
struct sd_cpu {
  int dummy;
};

/* Variables and functions */
struct sd_cpu *sd_cpu_get(struct sd_sys *, char const *);
struct sd_cpu *sd_cpu_new(struct sd_sys *, char const *, char *, int);
struct sd_cpu *l_cpu_alloc(struct sd_sys *guest, const char *id, int cnt) {
  struct sd_cpu *cpu = sd_cpu_get(guest, id);
  return cpu ? cpu : sd_cpu_new(guest, id, "UN", cnt);
}


x86 assembly (clang, -O0):
<l_cpu_alloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <sd_cpu_get@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     115c <l_cpu_alloc+0x3c>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1177 <l_cpu_alloc+0x57>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xe92(%rip),%rdx
call   1030 <sd_cpu_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_cpu_alloc>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <sd_cpu_get@plt>
test   %rax,%rax
je     113c <l_cpu_alloc+0x1c>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xebd(%rip),%rdx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%ecx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <sd_cpu_new@plt>

LLVM IR (-O0):
%struct.sd_cpu = type { i32 }
%struct.sd_sys = type { i32 }
@.str = [3 x i8] c"UN\00"
define %struct.sd_cpu* @l_cpu_alloc(%struct.sd_sys* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sd_sys*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.sd_cpu*
store %struct.sd_sys* %0, %struct.sd_sys** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load %struct.sd_sys*, %struct.sd_sys** %4
%9 = load i8*, i8** %5
%10 = call %struct.sd_cpu* @sd_cpu_get(%struct.sd_sys* %8, i8* %9)
store %struct.sd_cpu* %10, %struct.sd_cpu** %7
%11 = load %struct.sd_cpu*, %struct.sd_cpu** %7
%12 = icmp ne %struct.sd_cpu* %11, null
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = load %struct.sd_cpu*, %struct.sd_cpu** %7
br label %20
15: ; preds = %3
%16 = load %struct.sd_sys*, %struct.sd_sys** %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = call %struct.sd_cpu* @sd_cpu_new(%struct.sd_sys* %16, i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %15, %13
%21 = phi %struct.sd_cpu* [ %14, %13 ], [ %19, %15 ]
ret %struct.sd_cpu* %21
}

LLVM IR (-O2):
%struct.sd_cpu = type { i32 }
%struct.sd_sys = type { i32 }
@.str = [3 x i8] c"UN\00"
define %struct.sd_cpu* @l_cpu_alloc(%struct.sd_sys* %0, i8* %1, i32 %2) {
%4 = tail call %struct.sd_cpu* @sd_cpu_get(%struct.sd_sys* %0, i8* %1)
%5 = icmp eq %struct.sd_cpu* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call %struct.sd_cpu* @sd_cpu_new(%struct.sd_sys* %0, i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %2)
br label %8
8: ; preds = %3, %6
%9 = phi %struct.sd_cpu* [ %7, %6 ], [ %4, %3 ]
ret %struct.sd_cpu* %9
}