#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*/ TCSANOW;
int close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void closecpu(int *fd, struct termios *oldtio) {
  tcsetattr(*fd, TCSANOW, oldtio);
  int res = close(*fd);
  if (res < 0) {
    perror("/dev/ttyS0");
    exit(-1);
  } else
    printf("Closed device %s.\n", "/dev/ttyS0");
}


x86 assembly (clang, -O0):
<closecpu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11a6 <closecpu+0x56>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
lea    0xe5e(%rip),%rdi
lea    0xe4c(%rip),%rsi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closecpu>:
push   %rbx
mov    %rsi,%rdx
mov    %rdi,%rbx
mov    (%rdi),%edi
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1050 <tcsetattr@plt>
mov    (%rbx),%edi
call   1040 <close@plt>
test   %eax,%eax
js     1186 <closecpu+0x36>
lea    0xe92(%rip),%rdi
lea    0xe80(%rip),%rsi
pop    %rbx
jmp    1030 <printf@plt>
lea    0xe73(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [19 x i8] c"Closed device %s.\0A\00"
define void @closecpu(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* @TCSANOW
%9 = load %struct.termios*, %struct.termios** %4
%10 = call i32 @tcsetattr(i32 %7, i32 %8, %struct.termios* %9)
%11 = load i32*, i32** %3
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@TCSANOW = global i32 0
@.str = [11 x i8] c"/dev/ttyS0\00"
@.str.1 = [19 x i8] c"Closed device %s.\0A\00"
define void @closecpu(i32* nocapture %0, %struct.termios* %1) {
%3 = load i32, i32* %0
%4 = load i32, i32* @TCSANOW
%5 = tail call i32 @tcsetattr(i32 %3, i32 %4, %struct.termios* %1)
%6 = load i32, i32* %0
%7 = tail call i32 @close(i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 -1)
unreachable
12: ; preds = %2
%13 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
ret void
}