#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 */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, long);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int fd, retVal;
  long size;
  if (argc != 3) {
    printf("Syntax: %s <device> <size>\n\n", argv[0]);
    return 1;
  }
  size = strtol(argv[2], NULL, 10);
  printf("%s: new size: %ld bytes\n", argv[1], size);
  fd = open(argv[1], O_WRONLY, 0666);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  retVal = ioctl(fd, _IO(0xCE, 8), size);
  if (retVal != 0) {
    perror("ioctl");
    close(fd);
    return 1;
  }
  close(fd);
  return 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)
cmpl   $0x3,-0x8(%rbp)
je     11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1225 <main+0xb5>
lea    0xe22(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x114>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0xce,%edi
mov    $0x8,%esi
call   1040 <_IO@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1275 <main+0x105>
lea    0xddf(%rip),%rdi
call   1090 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x114>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
cmp    $0x3,%edi
jne    11eb <main+0x7b>
mov    0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %rax,%rbx
mov    0x8(%rbp),%rsi
lea    0xe84(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rbp),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1209 <main+0x99>
mov    %eax,%ebp
mov    $0xce,%edi
mov    $0x8,%esi
call   1040 <_IO@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <ioctl@plt>
test   %eax,%eax
jne    1217 <main+0xa7>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    1202 <main+0x92>
mov    0x0(%rbp),%rsi
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1090 <perror@plt>
jmp    11fd <main+0x8d>
lea    0xe1d(%rip),%rdi
call   1090 <perror@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11fd <main+0x8d>

LLVM IR (-O0):
@.str = [29 x i8] c"Syntax: %s <device> <size>\0A\0A\00"
@.str.1 = [25 x i8] c"%s: new size: %ld bytes\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\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 i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %49
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i64 @strtol(i8* %19, i32* null, i32 10)
store i64 %20, i64* %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i64, i64* %8
%25 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %23, i64 %24)
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i32, i32* @O_WRONLY
%30 = call i32 @open(i8* %28, i32 %29, i32 438)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %16
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %49
35: ; preds = %16
%36 = load i32, i32* %6
%37 = call i32 @_IO(i32 206, i32 8)
%38 = load i64, i64* %8
%39 = call i32 @ioctl(i32 %36, i32 %37, i64 %38)
store i32 %39, i32* %7
%40 = load i32, i32* %7
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
store i32 1, i32* %3
br label %49
46: ; preds = %35
%47 = load i32, i32* %6
%48 = call i32 @close(i32 %47)
store i32 0, i32* %3
br label %49
49: ; preds = %46, %42, %33, %11
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [29 x i8] c"Syntax: %s <device> <size>\0A\0A\00"
@.str.1 = [25 x i8] c"%s: new size: %ld bytes\0A\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %29
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @strtol(i8* nocapture %9, i32* null, i32 10)
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %12, i64 %10)
%14 = load i8*, i8** %11
%15 = load i32, i32* @O_WRONLY
%16 = tail call i32 @open(i8* %14, i32 %15, i32 438)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %29
20: ; preds = %7
%21 = tail call i32 @_IO(i32 206, i32 8)
%22 = tail call i32 @ioctl(i32 %16, i32 %21, i64 %10)
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%26 = tail call i32 @close(i32 %16)
br label %29
27: ; preds = %20
%28 = tail call i32 @close(i32 %16)
br label %29
29: ; preds = %27, %24, %18, %4
%30 = phi i32 [ 1, %4 ], [ 1, %18 ], [ 1, %24 ], [ 0, %27 ]
ret i32 %30
}