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

/* Variables and functions */
int /*<<< orphan*/ TCSAFLUSH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
void uart_close(int *uart_fd, struct termios *orig) {
  int err;
  err = tcsetattr(*uart_fd, TCSAFLUSH, orig);
  if (err < 0)
    fprintf(stdout, "tcsetattr() failed: %s\n", strerror(errno));
  close(*uart_fd);
}


x86 assembly (clang, -O0):
<uart_close>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a1 <uart_close+0x61>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uart_close>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rdx
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1050 <tcsetattr@plt>
test   %eax,%eax
jns    1185 <uart_close+0x45>
mov    0x2e6c(%rip),%rax
mov    (%rax),%ebp
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe85(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    (%rbx),%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <close@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
@stdout = global i32 0
@.str = [24 x i8] c"tcsetattr() failed: %s\0A\00"
@errno = global i32 0
define void @uart_close(i32* %0, %struct.termios* %1) {
%3 = alloca i32*
%4 = alloca %struct.termios*
%5 = alloca i32
store i32* %0, i32** %3
store %struct.termios* %1, %struct.termios** %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %6
%8 = load i32, i32* @TCSAFLUSH
%9 = load %struct.termios*, %struct.termios** %4
%10 = call i32 @tcsetattr(i32 %7, i32 %8, %struct.termios* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stdout
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %13, %2
%19 = load i32*, i32** %3
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSAFLUSH = global i32 0
@stdout = global i32 0
@.str = [24 x i8] c"tcsetattr() failed: %s\0A\00"
@errno = global i32 0
define void @uart_close(i32* nocapture %0, %struct.termios* %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* @TCSAFLUSH
%5 = tail call i32 @tcsetattr(i32 %3, i32 %4, %struct.termios* %1)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stdout
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %12
12: ; preds = %7, %2
%13 = load i32, i32* %0
%14 = tail call i32 @close(i32 %13)
ret void
}