#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 */
typedef struct TYPE_8__ TYPE_4__;
typedef struct TYPE_7__ TYPE_3__;
typedef struct TYPE_6__ TYPE_2__;
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_8__ {
  int offset;
  int length;
};
struct TYPE_7__ {
  int offset;
  int length;
};
struct TYPE_6__ {
  int offset;
  int length;
};
struct TYPE_5__ {
  int offset;
  int length;
};
struct fb_var_screeninfo {
  int xres;
  int yres;
  int bits_per_pixel;
  int line_length;
  TYPE_4__ transp;
  TYPE_3__ red;
  TYPE_2__ green;
  TYPE_1__ blue;
};
struct fb_fix_screeninfo {
  int xres;
  int yres;
  int bits_per_pixel;
  int line_length;
  TYPE_4__ transp;
  TYPE_3__ red;
  TYPE_2__ green;
  TYPE_1__ blue;
};

/* Variables and functions */
int /*<<< orphan*/ FBIOGET_FSCREENINFO;
int /*<<< orphan*/ FBIOGET_VSCREENINFO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct fb_var_screeninfo *);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int, int, int, int,
                           int, int, int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
int writeFBParams(int output_fd, int fb_fd) {
  struct fb_fix_screeninfo fb_fixinfo;
  struct fb_var_screeninfo fb_varinfo;
  if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_fixinfo) < 0) {
    fprintf(stderr, "External: fixinfo ioctl failed.");
    fprintf(stdout, "\n");
    close(fb_fd);
    return (1);
  }
  if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_varinfo) < 0) {
    fprintf(stderr, "External: varinfo ioctl failed.");
    fprintf(stdout, "\n");
    close(fb_fd);
    return (1);
  }
  char output_data[128] = {0};
  sprintf(output_data, "%u %u %u %u %u %u %u %u %u %u %u %u", fb_varinfo.xres,
          fb_varinfo.yres, fb_varinfo.bits_per_pixel, fb_varinfo.blue.offset,
          fb_varinfo.blue.length, fb_varinfo.green.offset,
          fb_varinfo.green.length, fb_varinfo.red.offset, fb_varinfo.red.length,
          fb_varinfo.transp.offset, fb_varinfo.transp.length,
          fb_fixinfo.line_length);
  write(output_fd, output_data, 128 * sizeof(char));
  return (0);
}


x86 assembly (clang, -O0):
<writeFBParams>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x138,%rsp
mov    %edi,-0x30(%rbp)
mov    %esi,-0x34(%rbp)
mov    -0x34(%rbp),%edi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11d7 <writeFBParams+0x77>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe62(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x2c(%rbp)
jmp    12d8 <writeFBParams+0x178>
mov    -0x34(%rbp),%edi
mov    0x2de7(%rip),%rax
mov    (%rax),%esi
lea    -0x98(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1237 <writeFBParams+0xd7>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x2c(%rbp)
jmp    12d8 <writeFBParams+0x178>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x98(%rbp),%edx
mov    -0x94(%rbp),%ecx
mov    -0x90(%rbp),%r8d
mov    -0x70(%rbp),%r9d
mov    -0x6c(%rbp),%r13d
mov    -0x78(%rbp),%r12d
mov    -0x74(%rbp),%r15d
mov    -0x80(%rbp),%r14d
mov    -0x7c(%rbp),%ebx
mov    -0x88(%rbp),%r11d
mov    -0x84(%rbp),%r10d
mov    -0x5c(%rbp),%eax
lea    0xdaf(%rip),%rsi
mov    %r13d,(%rsp)
mov    %r12d,0x8(%rsp)
mov    %r15d,0x10(%rsp)
mov    %r14d,0x18(%rsp)
mov    %ebx,0x20(%rsp)
mov    %r11d,0x28(%rsp)
mov    %r10d,0x30(%rsp)
mov    %eax,0x38(%rsp)
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x138,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeFBParams>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %esi,%ebp
mov    %edi,%r15d
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
lea    0xb8(%rsp),%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1248 <writeFBParams+0xf8>
mov    0x2e3a(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebp,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     125a <writeFBParams+0x10a>
xorps  %xmm0,%xmm0
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)
mov    (%rsp),%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x28(%rsp),%r9d
mov    0x2c(%rsp),%r10d
mov    0x20(%rsp),%r11d
mov    0x24(%rsp),%r12d
mov    0x18(%rsp),%r13d
mov    0x1c(%rsp),%ebp
mov    0x10(%rsp),%eax
mov    0x14(%rsp),%ebx
mov    0xc4(%rsp),%r14d
lea    0xe2b(%rip),%rsi
lea    0x30(%rsp),%rdi
push   %r14
push   %rbx
push   %rax
push   %rbp
push   %r13
push   %r12
push   %r11
push   %r10
call   1070 <sprintf@plt>
add    $0x40,%rsp
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    $0x80,%edx
call   1030 <write@plt>
xor    %eax,%eax
jmp    1290 <writeFBParams+0x140>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
jmp    126a <writeFBParams+0x11a>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
call   1060 <fprintf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
mov    $0x1,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.fb_fix_screeninfo = type { i32, i32, i32, i32, %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_8__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32 }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i32 }
%struct.fb_var_screeninfo = type { i32, i32, i32, i32, %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
@FBIOGET_FSCREENINFO = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"External: fixinfo ioctl failed.\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.2 = [32 x i8] c"External: varinfo ioctl failed.\00"
@.str.3 = [36 x i8] c"%u %u %u %u %u %u %u %u %u %u %u %u\00"
define i32 @writeFBParams(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.fb_fix_screeninfo
%7 = alloca %struct.fb_var_screeninfo
%8 = alloca [128 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %5
%10 = load i32, i32* @FBIOGET_FSCREENINFO
%11 = bitcast %struct.fb_fix_screeninfo* %6 to %struct.fb_var_screeninfo*
%12 = call i64 @ioctl(i32 %9, i32 %10, %struct.fb_var_screeninfo* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @stdout
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = load i32, i32* %5
%20 = call i32 @close(i32 %19)
store i32 1, i32* %3
br label %72
21: ; preds = %2
%22 = load i32, i32* %5
%23 = load i32, i32* @FBIOGET_VSCREENINFO
%24 = call i64 @ioctl(i32 %22, i32 %23, %struct.fb_var_screeninfo* %7)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load i32, i32* %5
%32 = call i32 @close(i32 %31)
store i32 1, i32* %3
br label %72
33: ; preds = %21
%34 = bitcast [128 x i8]* %8 to i8*
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%36 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 2
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 7
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 7
%46 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 6
%49 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 6
%52 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %51, i32 0, i32 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 5
%55 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 5
%58 = getelementptr inbounds %struct.TYPE_7__, %struct.TYPE_7__* %57, i32 0, i32 1
%59 = load i32, i32* %58
%60 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 4
%61 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %7, i32 0, i32 4
%64 = getelementptr inbounds %struct.TYPE_8__, %struct.TYPE_8__* %63, i32 0, i32 1
%65 = load i32, i32* %64
%66 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %6, i32 0, i32 3
%67 = load i32, i32* %66
%68 = call i32 @sprintf(i8* %35, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %37, i32 %39, i32 %41, i32 %44, i32 %47, i32 %50, i32 %53, i32 %56, i32 %59, i32 %62, i32 %65, i32 %67)
%69 = load i32, i32* %4
%70 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%71 = call i32 @write(i32 %69, i8* %70, i32 128)
store i32 0, i32* %3
br label %72
72: ; preds = %33, %26, %14
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
%struct.fb_fix_screeninfo = type { i32, i32, i32, i32, %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
%struct.TYPE_8__ = type { i32, i32 }
%struct.TYPE_7__ = type { i32, i32 }
%struct.TYPE_6__ = type { i32, i32 }
%struct.TYPE_5__ = type { i32, i32 }
%struct.fb_var_screeninfo = type { i32, i32, i32, i32, %struct.TYPE_8__, %struct.TYPE_7__, %struct.TYPE_6__, %struct.TYPE_5__ }
@FBIOGET_FSCREENINFO = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"External: fixinfo ioctl failed.\00"
@stdout = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@FBIOGET_VSCREENINFO = global i32 0
@.str.2 = [32 x i8] c"External: varinfo ioctl failed.\00"
@.str.3 = [36 x i8] c"%u %u %u %u %u %u %u %u %u %u %u %u\00"
define i32 @writeFBParams(i32 %0, i32 %1) {
%3 = alloca %struct.fb_fix_screeninfo
%4 = alloca %struct.fb_var_screeninfo
%5 = alloca [128 x i8]
%6 = bitcast %struct.fb_fix_screeninfo* %3 to i8*
%7 = bitcast %struct.fb_var_screeninfo* %4 to i8*
%8 = load i32, i32* @FBIOGET_FSCREENINFO
%9 = bitcast %struct.fb_fix_screeninfo* %3 to %struct.fb_var_screeninfo*
%10 = call i64 @ioctl(i32 %1, i32 %8, %struct.fb_var_screeninfo* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stdout
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @close(i32 %1)
br label %56
18: ; preds = %2
%19 = load i32, i32* @FBIOGET_VSCREENINFO
%20 = call i64 @ioctl(i32 %1, i32 %19, %struct.fb_var_screeninfo* %4)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* @stdout
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @close(i32 %1)
br label %56
28: ; preds = %18
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%30 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 1
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 2
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 7, i32 0
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 7, i32 1
%39 = load i32, i32* %38
%40 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 6, i32 0
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 6, i32 1
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 5, i32 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 5, i32 1
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 4, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.fb_var_screeninfo, %struct.fb_var_screeninfo* %4, i64 0, i32 4, i32 1
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.fb_fix_screeninfo, %struct.fb_fix_screeninfo* %3, i64 0, i32 3
%53 = load i32, i32* %52
%54 = call i32 @sprintf(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %33, i32 %35, i32 %37, i32 %39, i32 %41, i32 %43, i32 %45, i32 %47, i32 %49, i32 %51, i32 %53)
%55 = call i32 @write(i32 %0, i8* %29, i32 128)
br label %56
56: ; preds = %28, %22, %12
%57 = phi i32 [ 1, %12 ], [ 1, %22 ], [ 0, %28 ]
ret i32 %57
}