#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 */

/* Variables and functions */
short atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
short htons(short);
int /*<<< orphan*/ ioctl_setdpy(int, short);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  int file_desc, ret_val;
  char *msg = "Message passed by ioctl\n";
  short int val = 0x7733;
  file_desc = open("/dev/fpga", 0);
  if (file_desc < 0) {
    printf("Can't open device file: %s\n", "/dev/fpga");
    exit(-1);
  }
  if (argc >= 2) {
    val = atoi(argv[1]);
  } else
    val = htons(val);
  ioctl_setdpy(file_desc, val);
  close(file_desc);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
movw   $0x7733,-0x22(%rbp)
lea    0xe7b(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cf <main+0x5f>
lea    0xe6a(%rip),%rdi
lea    0xe59(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jl     11ef <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %ax,-0x22(%rbp)
jmp    11fc <main+0x8c>
movswl -0x22(%rbp),%edi
call   1030 <htons@plt>
mov    %ax,-0x22(%rbp)
mov    -0x14(%rbp),%edi
movswl -0x22(%rbp),%esi
call   1060 <ioctl_setdpy@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe80(%rip),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
jns    11a8 <main+0x38>
lea    0xe78(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    %eax,%ebx
cmp    $0x2,%ebp
jl     11ba <main+0x4a>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
jmp    11c4 <main+0x54>
mov    $0x7733,%edi
call   1030 <htons@plt>
movswl %ax,%esi
mov    %ebx,%edi
call   1060 <ioctl_setdpy@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Message passed by ioctl\0A\00"
@.str.1 = [10 x i8] c"/dev/fpga\00"
@.str.2 = [28 x i8] c"Can't open device file: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %8
store i16 30515, i16* %9
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp sge i32 %17, 2
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call signext i16 @atoi(i8* %22)
store i16 %23, i16* %9
br label %27
24: ; preds = %16
%25 = load i16, i16* %9
%26 = call signext i16 @htons(i16 signext %25)
store i16 %26, i16* %9
br label %27
27: ; preds = %24, %19
%28 = load i32, i32* %6
%29 = load i16, i16* %9
%30 = call i32 @ioctl_setdpy(i32 %28, i16 signext %29)
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
%33 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"/dev/fpga\00"
@.str.2 = [28 x i8] c"Can't open device file: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %14
10: ; preds = %8
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call signext i16 @atoi(i8* %12)
br label %16
14: ; preds = %8
%15 = tail call signext i16 @htons(i16 signext 30515)
br label %16
16: ; preds = %14, %10
%17 = phi i16 [ %13, %10 ], [ %15, %14 ]
%18 = tail call i32 @ioctl_setdpy(i32 %3, i16 signext %17)
%19 = tail call i32 @close(i32 %3)
%20 = tail call i32 @exit(i32 0)
unreachable
}