#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*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ TCGETS;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int ioctl(int /*<<< orphan*/, int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  char buf[256] = {0};
  struct termios tty = {0};
  scanf("%s", buf);
  if (ioctl(0, TCGETS, &tty) == -1) {
    fprintf(stderr, "failure\n");
    printf("buf = %s\n", buf);
    return -1;
  } else {
    printf("success\n");
    printf("buf = %s\n", buf);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x118(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x118(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11f1 <main+0xa1>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1060 <fprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121b <main+0xcb>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x110,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xe2b(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
xor    %ebx,%ebx
lea    0x8(%rsp),%rdx
xor    %edi,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0xb9>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
jmp    1223 <main+0xd3>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
lea    0xde2(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [3 x i8] c"%s\00"
@TCGETS = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"failure\0A\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@.str.3 = [9 x i8] c"success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca %struct.termios
store i32 0, i32* %1
%4 = bitcast [256 x i8]* %2 to i8*
%5 = bitcast %struct.termios* %3 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @TCGETS
%9 = call i32 @ioctl(i32 0, i32 %8, %struct.termios* %3)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %14)
store i32 -1, i32* %1
br label %20
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %18)
store i32 0, i32* %1
br label %20
20: ; preds = %16, %11
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@.str = [3 x i8] c"%s\00"
@TCGETS = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"failure\0A\00"
@.str.2 = [10 x i8] c"buf = %s\0A\00"
@str = [8 x i8] c"success\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca %struct.termios
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.termios* %2 to i8*
%5 = getelementptr inbounds %struct.termios, %struct.termios* %2, i64 0, i32 0
store i32 0, i32* %5
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = load i32, i32* @TCGETS
%8 = call i32 @ioctl(i32 0, i32 %7, %struct.termios* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %15
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = phi i32 [ -1, %10 ], [ 0, %13 ]
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %3)
ret i32 %16
}