#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 socketlist {
  int dummy;
};
struct socket {
  int dummy;
};
struct addrinfo {
  int dummy;
};

/* Variables and functions */
struct socket *socket_new(int, struct addrinfo *);
int /*<<< orphan*/ socketlist_put(struct socketlist *, struct socket *);
struct socket *socketlist_register(struct socketlist *head, int fd,
                                   struct addrinfo *ai) {
  struct socket *s = socket_new(fd, ai);
  if (s == 0)
    return 0;
  socketlist_put(head, s);
  return s;
}


x86 assembly (clang, -O0):
<socketlist_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <socket_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    115b <socketlist_register+0x3b>
movq   $0x0,-0x8(%rbp)
jmp    1170 <socketlist_register+0x50>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <socketlist_put@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socketlist_register>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%edi
mov    %rdx,%rsi
call   1030 <socket_new@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1144 <socketlist_register+0x24>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <socketlist_put@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.socket = type { i32 }
%struct.socketlist = type { i32 }
%struct.addrinfo = type { i32 }
define %struct.socket* @socketlist_register(%struct.socketlist* %0, i32 %1, %struct.addrinfo* %2) {
%4 = tail call %struct.socket* @socket_new(i32 %1, %struct.addrinfo* %2)
%5 = icmp eq %struct.socket* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @socketlist_put(%struct.socketlist* %0, %struct.socket* %4)
br label %8
8: ; preds = %3, %6
ret %struct.socket* %4
}