#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 {
  scalar_t__ c_iflag;
  scalar_t__ c_oflag;
  scalar_t__ c_cflag;
  scalar_t__ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ printf(char *, ...);
int tcgetattr(int, struct termios *);
int tcsetattr(int, int /*<<< orphan*/, struct termios *);
struct termios setTerms(int fd, struct termios config) {
  int setflag = tcsetattr(fd, TCSANOW, &config);
  if (setflag < 0) {
    printf("setTerms: setflag = %i\n", setflag);
  }
  struct termios testterm = config;
  setflag = tcgetattr(fd, &testterm);
  if (setflag < 0) {
    printf("setTerms: getflag = %i\n", setflag);
  }
  if (config.c_iflag != testterm.c_iflag) {
    printf("setTerms: c_iflags didn't set properly.\n");
  }
  if (config.c_oflag != testterm.c_oflag) {
    printf("setTerms: c_oflags didn't set properly.\n");
  }
  if (config.c_cflag != testterm.c_cflag) {
    printf("setTerms: c_cflags didn't set properly.\n");
  }
  if (config.c_lflag != testterm.c_lflag) {
    printf("setTerms: c_lflags didn't set properly.\n");
  }
  return testterm;
}


x86 assembly (clang, -O0):
<setTerms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rdi,-0x18(%rbp)
lea    0x10(%rbp),%rdx
mov    %rdx,-0x10(%rbp)
mov    %esi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1050 <tcsetattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117a <setTerms+0x4a>
mov    -0x8(%rbp),%esi
lea    0xe8d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,(%rsi)
mov    0x8(%rax),%rcx
mov    %rcx,0x8(%rsi)
mov    0x10(%rax),%rcx
mov    %rcx,0x10(%rsi)
mov    0x18(%rax),%rax
mov    %rax,0x18(%rsi)
mov    -0x4(%rbp),%edi
call   1040 <tcgetattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11c6 <setTerms+0x96>
mov    -0x8(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    (%rcx),%rax
je     11e8 <setTerms+0xb8>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmp    0x8(%rcx),%rax
je     120c <setTerms+0xdc>
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
cmp    0x10(%rcx),%rax
je     1230 <setTerms+0x100>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
cmp    0x18(%rcx),%rax
je     1254 <setTerms+0x124>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setTerms>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x20(%rsp),%r14
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14,%rdx
call   1060 <tcsetattr@plt>
test   %eax,%eax
jns    1175 <setTerms+0x35>
lea    0xe94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movups (%r14),%xmm0
movups 0x10(%r14),%xmm1
movups %xmm1,0x10(%rbx)
movups %xmm0,(%rbx)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
test   %eax,%eax
jns    11a3 <setTerms+0x63>
lea    0xe7e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%rax
cmp    (%rbx),%rax
je     11b7 <setTerms+0x77>
lea    0xef6(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rax
cmp    0x8(%rbx),%rax
je     11cd <setTerms+0x8d>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%r14),%rax
cmp    0x10(%rbx),%rax
je     11e3 <setTerms+0xa3>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%r14),%rax
cmp    0x18(%rbx),%rax
je     11f9 <setTerms+0xb9>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i64, i64, i64, i64 }
@TCSANOW = global i32 0
@.str = [24 x i8] c"setTerms: setflag = %i\0A\00"
@.str.1 = [24 x i8] c"setTerms: getflag = %i\0A\00"
@.str.2 = [41 x i8] c"setTerms: c_iflags didn't set properly.\0A\00"
@.str.3 = [41 x i8] c"setTerms: c_oflags didn't set properly.\0A\00"
@.str.4 = [41 x i8] c"setTerms: c_cflags didn't set properly.\0A\00"
@.str.5 = [41 x i8] c"setTerms: c_lflags didn't set properly.\0A\00"
define void @setTerms(%struct.termios* noalias sret(%struct.termios) align 8 %0, i32 %1, %struct.termios* byval(%struct.termios) align 8 %2) {
%4 = alloca i32
%5 = alloca i32
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* @TCSANOW
%8 = call i32 @tcsetattr(i32 %6, i32 %7, %struct.termios* %2)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %11, %3
%15 = bitcast %struct.termios* %0 to i8*
%16 = bitcast %struct.termios* %2 to i8*
%17 = load i32, i32* %4
%18 = call i32 @tcgetattr(i32 %17, %struct.termios* %0)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i32, i32* %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %14
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %0, i32 0, i32 0
%28 = load i64, i64* %27
%29 = icmp ne i64 %26, %28
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.termios, %struct.termios* %0, i32 0, i32 1
%36 = load i64, i64* %35
%37 = icmp ne i64 %34, %36
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
%41 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 2
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.termios, %struct.termios* %0, i32 0, i32 2
%44 = load i64, i64* %43
%45 = icmp ne i64 %42, %44
br i1 %45, label %46, label %48
46: ; preds = %40
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %40
%49 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 3
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.termios, %struct.termios* %0, i32 0, i32 3
%52 = load i64, i64* %51
%53 = icmp ne i64 %50, %52
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
ret void
}

LLVM IR (-O2):
%struct.termios = type { i64, i64, i64, i64 }
@TCSANOW = global i32 0
@.str = [24 x i8] c"setTerms: setflag = %i\0A\00"
@.str.1 = [24 x i8] c"setTerms: getflag = %i\0A\00"
@str = [40 x i8] c"setTerms: c_lflags didn't set properly.\00"
@str.6 = [40 x i8] c"setTerms: c_cflags didn't set properly.\00"
@str.7 = [40 x i8] c"setTerms: c_oflags didn't set properly.\00"
@str.8 = [40 x i8] c"setTerms: c_iflags didn't set properly.\00"
define void @setTerms(%struct.termios* noalias sret(%struct.termios) align 8 %0, i32 %1, %struct.termios* byval(%struct.termios) align 8 %2) {
%4 = load i32, i32* @TCSANOW
%5 = call i32 @tcsetattr(i32 %1, i32 %4, %struct.termios* %2)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %9
9: ; preds = %7, %3
%10 = bitcast %struct.termios* %0 to i8*
%11 = bitcast %struct.termios* %2 to i8*
%12 = call i32 @tcgetattr(i32 %1, %struct.termios* %0)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %9
%17 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 0
%20 = load i64, i64* %19
%21 = icmp eq i64 %18, %20
br i1 %21, label %24, label %22
22: ; preds = %16
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.8, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 1
%26 = load i64, i64* %25
%27 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 1
%28 = load i64, i64* %27
%29 = icmp eq i64 %26, %28
br i1 %29, label %32, label %30
30: ; preds = %24
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.7, i64 0, i64 0))
br label %32
32: ; preds = %30, %24
%33 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 2
%34 = load i64, i64* %33
%35 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 2
%36 = load i64, i64* %35
%37 = icmp eq i64 %34, %36
br i1 %37, label %40, label %38
38: ; preds = %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.6, i64 0, i64 0))
br label %40
40: ; preds = %38, %32
%41 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 3
%42 = load i64, i64* %41
%43 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 3
%44 = load i64, i64* %43
%45 = icmp eq i64 %42, %44
br i1 %45, label %48, label %46
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %48
48: ; preds = %46, %40
ret void
}