#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 TCGETS;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int ioctl(int /*<<< orphan*/, int, struct termios *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  struct termios t;
  int ret;
  printf("TCGETS = 0x%08x\n", TCGETS);
  printf("sizeof(struct termios) = %ld\n", (long)sizeof(struct termios));
  ret = ioctl(fileno(stdout), TCGETS, &t);
  if (ret < 0) {
    perror("ioctl");
  } else {
    printf("ioctl returned %d\n", ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%esi
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    %eax,%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bc <main+0x7c>
lea    0xe7d(%rip),%rdi
call   1060 <perror@plt>
jmp    11cb <main+0x8b>
mov    -0x1c(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rbx
mov    (%rbx),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1050 <fileno@plt>
mov    (%rbx),%esi
lea    0x8(%rsp),%rdx
mov    %eax,%edi
call   1040 <ioctl@plt>
test   %eax,%eax
js     11a1 <main+0x61>
lea    0xea3(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe87(%rip),%rdi
call   1060 <perror@plt>
jmp    1199 <main+0x59>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [17 x i8] c"TCGETS = 0x%08x\0A\00"
@TCGETS = global i32 0
@.str.1 = [30 x i8] c"sizeof(struct termios) = %ld\0A\00"
@stdout = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [19 x i8] c"ioctl returned %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.termios
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @TCGETS
%9 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 4)
%11 = load i32, i32* @stdout
%12 = call i32 @fileno(i32 %11)
%13 = load i32, i32* @TCGETS
%14 = call i32 @ioctl(i32 %12, i32 %13, %struct.termios* %6)
store i32 %14, i32* %7
%15 = load i32, i32* %7
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %22
19: ; preds = %2
%20 = load i32, i32* %7
%21 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %19, %17
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [17 x i8] c"TCGETS = 0x%08x\0A\00"
@TCGETS = global i32 0
@.str.1 = [30 x i8] c"sizeof(struct termios) = %ld\0A\00"
@stdout = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@.str.3 = [19 x i8] c"ioctl returned %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = load i32, i32* @TCGETS
%6 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 4)
%8 = load i32, i32* @stdout
%9 = tail call i32 @fileno(i32 %8)
%10 = load i32, i32* @TCGETS
%11 = call i32 @ioctl(i32 %9, i32 %10, %struct.termios* %3)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %17
17: ; preds = %15, %13
ret i32 0
}