#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 rtc_device {
  int dummy;
};
struct i2c_client {
  int dummy;
};

/* Variables and functions */
int i2c_detach_client(struct i2c_client *);
struct rtc_device *i2c_get_clientdata(struct i2c_client *);
int /*<<< orphan*/ kfree(struct i2c_client *);
int /*<<< orphan*/ rtc_device_unregister(struct rtc_device *);
int ds1672_detach(struct i2c_client *client) {
  int err;
  struct rtc_device *rtc = i2c_get_clientdata(client);
  if (rtc)
    rtc_device_unregister(rtc);
  if ((err = i2c_detach_client(client)))
    return err;
  kfree(client);
  return 0;
}


x86 assembly (clang, -O0):
<ds1672_detach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <i2c_get_clientdata@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     116d <ds1672_detach+0x2d>
mov    -0x20(%rbp),%rdi
call   1060 <rtc_device_unregister@plt>
mov    -0x10(%rbp),%rdi
call   1050 <i2c_detach_client@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     118d <ds1672_detach+0x4d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119d <ds1672_detach+0x5d>
mov    -0x10(%rbp),%rdi
call   1040 <kfree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds1672_detach>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <i2c_get_clientdata@plt>
test   %rax,%rax
je     1158 <ds1672_detach+0x18>
mov    %rax,%rdi
call   1060 <rtc_device_unregister@plt>
mov    %rbx,%rdi
call   1050 <i2c_detach_client@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    116e <ds1672_detach+0x2e>
mov    %rbx,%rdi
call   1040 <kfree@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.i2c_client = type { i32 }
%struct.rtc_device = type { i32 }
define i32 @ds1672_detach(%struct.i2c_client* %0) {
%2 = tail call %struct.rtc_device* @i2c_get_clientdata(%struct.i2c_client* %0)
%3 = icmp eq %struct.rtc_device* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @rtc_device_unregister(%struct.rtc_device* %2)
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @i2c_detach_client(%struct.i2c_client* %0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @kfree(%struct.i2c_client* %0)
br label %11
11: ; preds = %6, %9
ret i32 %7
}