#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 /*<<< orphan*/ *c_cc;
  int /*<<< orphan*/ c_ospeed;
  int /*<<< orphan*/ c_ispeed;
  int /*<<< orphan*/ c_lflag;
  int /*<<< orphan*/ c_cflag;
  int /*<<< orphan*/ c_oflag;
  int /*<<< orphan*/ c_iflag;
};

/* Variables and functions */
int NCCS;
int log_get_level();
int /*<<< orphan*/ log_write(char *, ...);
int /*<<< orphan*/ serial_print_bits(int /*<<< orphan*/);
void serial_print_termios(struct termios *tio, char *label) {
  int i;
  int cc = 0;
  if (log_get_level() < 1)
    return;
  if (label) {
    log_write("termios state: %s\n", label);
  }
  log_write("c_iflag: 0x%08x ", tio->c_iflag);
  serial_print_bits(tio->c_iflag);
  log_write("\nc_oflag: 0x%08x ", tio->c_oflag);
  serial_print_bits(tio->c_oflag);
  log_write("\nc_cflag: 0x%08x ", tio->c_cflag);
  serial_print_bits(tio->c_cflag);
  log_write("\nc_lflag: 0x%08x ", tio->c_lflag);
  serial_print_bits(tio->c_lflag);
  log_write("\nc_ispeed: %d\n", tio->c_ispeed);
  log_write("c_ospeed: %d\n", tio->c_ospeed);
  if (cc) {
    for (i = 0; i < NCCS; ++i) {
      log_write("c_cc[%02d] = %3hhu ", i, tio->c_cc[i]);
      switch (i) {
      case 16:
        log_write("(VTIME)\n");
        break;
      case 17:
        log_write("(VMIN)\n");
        break;
      default:
        log_write("\n");
      }
    }
    log_write("\n");
  }
}


x86 assembly (clang, -O0):
<serial_print_termios>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <log_get_level@plt>
cmp    $0x1,%eax
jge    115c <serial_print_termios+0x2c>
jmp    12e2 <serial_print_termios+0x1b2>
cmpq   $0x0,-0x10(%rbp)
je     1179 <serial_print_termios+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%esi
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x1c(%rax),%edi
call   1030 <serial_print_bits@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%esi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x18(%rax),%edi
call   1030 <serial_print_bits@plt>
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x14(%rax),%edi
call   1030 <serial_print_bits@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x10(%rax),%edi
call   1030 <serial_print_bits@plt>
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%esi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
cmpl   $0x0,-0x18(%rbp)
je     12e2 <serial_print_termios+0x1b2>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2dae(%rip),%rcx
cmp    (%rcx),%eax
jge    12d4 <serial_print_termios+0x1a4>
movslq -0x14(%rbp),%rcx
mov    %ecx,%esi
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax,%rcx,4),%edx
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x10,%eax
je     128d <serial_print_termios+0x15d>
jmp    127c <serial_print_termios+0x14c>
mov    -0x1c(%rbp),%eax
sub    $0x11,%eax
je     12a0 <serial_print_termios+0x170>
jmp    12b3 <serial_print_termios+0x183>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    12c1 <serial_print_termios+0x191>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    12c1 <serial_print_termios+0x191>
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
jmp    12c6 <serial_print_termios+0x196>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1238 <serial_print_termios+0x108>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1050 <log_write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serial_print_termios>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <log_get_level@plt>
test   %eax,%eax
jle    11ec <serial_print_termios+0xbc>
test   %r14,%r14
je     115f <serial_print_termios+0x2f>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x1c(%rbx),%esi
lea    0xeaa(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x1c(%rbx),%edi
call   1030 <serial_print_bits@plt>
mov    0x18(%rbx),%esi
lea    0xea2(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x18(%rbx),%edi
call   1030 <serial_print_bits@plt>
mov    0x14(%rbx),%esi
lea    0xe9b(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x14(%rbx),%edi
call   1030 <serial_print_bits@plt>
mov    0x10(%rbx),%esi
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x10(%rbx),%edi
call   1030 <serial_print_bits@plt>
mov    0xc(%rbx),%esi
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1050 <log_write@plt>
mov    0x8(%rbx),%esi
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <log_write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32*, i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"termios state: %s\0A\00"
@.str.1 = [17 x i8] c"c_iflag: 0x%08x \00"
@.str.2 = [18 x i8] c"\0Ac_oflag: 0x%08x \00"
@.str.3 = [18 x i8] c"\0Ac_cflag: 0x%08x \00"
@.str.4 = [18 x i8] c"\0Ac_lflag: 0x%08x \00"
@.str.5 = [15 x i8] c"\0Ac_ispeed: %d\0A\00"
@.str.6 = [14 x i8] c"c_ospeed: %d\0A\00"
@NCCS = global i32 0
@.str.7 = [20 x i8] c"c_cc[%02d] = %3hhu \00"
@.str.8 = [9 x i8] c"(VTIME)\0A\00"
@.str.9 = [8 x i8] c"(VMIN)\0A\00"
@.str.10 = [2 x i8] c"\0A\00"
define void @serial_print_termios(%struct.termios* %0, i8* %1) {
%3 = alloca %struct.termios*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store %struct.termios* %0, %struct.termios** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = call i32 (...) @log_get_level()
%8 = icmp slt i32 %7, 1
br i1 %8, label %9, label %10
9: ; preds = %2
br label %87
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %13, %10
%17 = load %struct.termios*, %struct.termios** %3
%18 = getelementptr inbounds %struct.termios, %struct.termios* %17, i32 0, i32 6
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load %struct.termios*, %struct.termios** %3
%22 = getelementptr inbounds %struct.termios, %struct.termios* %21, i32 0, i32 6
%23 = load i32, i32* %22
%24 = call i32 @serial_print_bits(i32 %23)
%25 = load %struct.termios*, %struct.termios** %3
%26 = getelementptr inbounds %struct.termios, %struct.termios* %25, i32 0, i32 5
%27 = load i32, i32* %26
%28 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load %struct.termios*, %struct.termios** %3
%30 = getelementptr inbounds %struct.termios, %struct.termios* %29, i32 0, i32 5
%31 = load i32, i32* %30
%32 = call i32 @serial_print_bits(i32 %31)
%33 = load %struct.termios*, %struct.termios** %3
%34 = getelementptr inbounds %struct.termios, %struct.termios* %33, i32 0, i32 4
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load %struct.termios*, %struct.termios** %3
%38 = getelementptr inbounds %struct.termios, %struct.termios* %37, i32 0, i32 4
%39 = load i32, i32* %38
%40 = call i32 @serial_print_bits(i32 %39)
%41 = load %struct.termios*, %struct.termios** %3
%42 = getelementptr inbounds %struct.termios, %struct.termios* %41, i32 0, i32 3
%43 = load i32, i32* %42
%44 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %43)
%45 = load %struct.termios*, %struct.termios** %3
%46 = getelementptr inbounds %struct.termios, %struct.termios* %45, i32 0, i32 3
%47 = load i32, i32* %46
%48 = call i32 @serial_print_bits(i32 %47)
%49 = load %struct.termios*, %struct.termios** %3
%50 = getelementptr inbounds %struct.termios, %struct.termios* %49, i32 0, i32 2
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %51)
%53 = load %struct.termios*, %struct.termios** %3
%54 = getelementptr inbounds %struct.termios, %struct.termios* %53, i32 0, i32 1
%55 = load i32, i32* %54
%56 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %55)
%57 = load i32, i32* %6
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %87
59: ; preds = %16
store i32 0, i32* %5
br label %60
60: ; preds = %82, %59
%61 = load i32, i32* %5
%62 = load i32, i32* @NCCS
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %85
64: ; preds = %60
%65 = load i32, i32* %5
%66 = load %struct.termios*, %struct.termios** %3
%67 = getelementptr inbounds %struct.termios, %struct.termios* %66, i32 0, i32 0
%68 = load i32*, i32** %67
%69 = load i32, i32* %5
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i32, i32* %68, i64 %70
%72 = load i32, i32* %71
%73 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %65, i32 %72)
%74 = load i32, i32* %5
switch i32 %74, label %79 [
i32 16, label %75
i32 17, label %77
]
75: ; preds = %64
%76 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %81
77: ; preds = %64
%78 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %81
79: ; preds = %64
%80 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %81
81: ; preds = %79, %77, %75
br label %82
82: ; preds = %81
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %60
85: ; preds = %60
%86 = call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %87
87: ; preds = %9, %85, %16
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32, i32, i32, i32, i32, i32 }
@.str = [19 x i8] c"termios state: %s\0A\00"
@.str.1 = [17 x i8] c"c_iflag: 0x%08x \00"
@.str.2 = [18 x i8] c"\0Ac_oflag: 0x%08x \00"
@.str.3 = [18 x i8] c"\0Ac_cflag: 0x%08x \00"
@.str.4 = [18 x i8] c"\0Ac_lflag: 0x%08x \00"
@.str.5 = [15 x i8] c"\0Ac_ispeed: %d\0A\00"
@.str.6 = [14 x i8] c"c_ospeed: %d\0A\00"
@NCCS = global i32 0
define void @serial_print_termios(%struct.termios* nocapture %0, i8* %1) {
%3 = tail call i32 (...) @log_get_level()
%4 = icmp slt i32 %3, 1
br i1 %4, label %36, label %5
5: ; preds = %2
%6 = icmp eq i8* %1, null
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %9
9: ; preds = %7, %5
%10 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 6
%11 = load i32, i32* %10
%12 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %10
%14 = tail call i32 @serial_print_bits(i32 %13)
%15 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 5
%16 = load i32, i32* %15
%17 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %15
%19 = tail call i32 @serial_print_bits(i32 %18)
%20 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 4
%21 = load i32, i32* %20
%22 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = load i32, i32* %20
%24 = tail call i32 @serial_print_bits(i32 %23)
%25 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 3
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %25
%29 = tail call i32 @serial_print_bits(i32 %28)
%30 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 2
%31 = load i32, i32* %30
%32 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds %struct.termios, %struct.termios* %0, i64 0, i32 1
%34 = load i32, i32* %33
%35 = tail call i32 (i8*, ...) @log_write(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %2, %9
ret void
}