#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 serial {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ serial_destroy(struct serial *);
struct serial *serial_init(char *, int, int);
void serial_destroy_and_init(struct serial **dev, char *serialport, int bps) {
  if (*dev != NULL)
    serial_destroy(*dev);
  *dev = serial_init(serialport, bps,
                     (0x01 << 5) | (0x01 << 0) | (0x01 << 3) | (0x01 << 8) |
                         (0x01 << 10));
  if (*dev == NULL) {
    printf("\x1b[31;1mERROR\x1b[0m"
           " could not open serial port '%s'\n",
           serialport);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<serial_destroy_and_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     116d <serial_destroy_and_init+0x2d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <serial_destroy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x529,%edx
call   1060 <serial_init@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b0 <serial_destroy_and_init+0x70>
mov    -0x10(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_destroy_and_init>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rdi
test   %rdi,%rdi
je     1159 <serial_destroy_and_init+0x19>
call   1040 <serial_destroy@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    $0x529,%edx
call   1060 <serial_init@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1175 <serial_destroy_and_init+0x35>
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe84(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.serial = type { i32 }
@.str = [50 x i8] c"\1B[31;1mERROR\1B[0m could not open serial port '%s'\0A\00"
define void @serial_destroy_and_init(%struct.serial** %0, i8* %1, i32 %2) {
%4 = alloca %struct.serial**
%5 = alloca i8*
%6 = alloca i32
store %struct.serial** %0, %struct.serial*** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%7 = load %struct.serial**, %struct.serial*** %4
%8 = load %struct.serial*, %struct.serial** %7
%9 = icmp ne %struct.serial* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load %struct.serial**, %struct.serial*** %4
%12 = load %struct.serial*, %struct.serial** %11
%13 = call i32 @serial_destroy(%struct.serial* %12)
br label %14
14: ; preds = %10, %3
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = call %struct.serial* @serial_init(i8* %15, i32 %16, i32 1321)
%18 = load %struct.serial**, %struct.serial*** %4
store %struct.serial* %17, %struct.serial** %18
%19 = load %struct.serial**, %struct.serial*** %4
%20 = load %struct.serial*, %struct.serial** %19
%21 = icmp eq %struct.serial* %20, null
br i1 %21, label %22, label %26
22: ; preds = %14
%23 = load i8*, i8** %5
%24 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.serial = type { i32 }
@.str = [50 x i8] c"\1B[31;1mERROR\1B[0m could not open serial port '%s'\0A\00"
define void @serial_destroy_and_init(%struct.serial** nocapture %0, i8* %1, i32 %2) {
%4 = load %struct.serial*, %struct.serial** %0
%5 = icmp eq %struct.serial* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @serial_destroy(%struct.serial* %4)
br label %8
8: ; preds = %6, %3
%9 = tail call %struct.serial* @serial_init(i8* %1, i32 %2, i32 1321)
store %struct.serial* %9, %struct.serial** %0
%10 = icmp eq %struct.serial* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = tail call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %1)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8
ret void
}