#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 */
typedef int uint;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ writeToDeviceForRead(int, int);
void readFromDevice(int fd, int reg) {
  writeToDeviceForRead(fd, reg);
  char buf[1];
  printf("Reading from reg %i", (uint)reg);
  buf[0] = reg + 27;
  if (read(fd, buf, 1) != 1) {
    fprintf(stderr, "Can't write to device\n");
  } else {
    printf("asdlfkjasldfjlksd\n");
    printf("Read %i from buf\n", (uint)buf[0]);
  }
}


x86 assembly (clang, -O0):
<readFromDevice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1060 <writeToDeviceForRead@plt>
mov    -0x8(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1b,%eax
mov    %al,-0x9(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x1,%eax
je     11a7 <readFromDevice+0x67>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11c7 <readFromDevice+0x87>
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x9(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFromDevice>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1070 <writeToDeviceForRead@plt>
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1b,%bl
mov    %bl,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x1,%eax
jne    11ae <readFromDevice+0x5e>
lea    0xead(%rip),%rdi
call   1030 <puts@plt>
movsbl 0x7(%rsp),%esi
lea    0xe8a(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <fprintf@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"Reading from reg %i\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can't write to device\0A\00"
@.str.2 = [19 x i8] c"asdlfkjasldfjlksd\0A\00"
@.str.3 = [18 x i8] c"Read %i from buf\0A\00"
define void @readFromDevice(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = load i32, i32* %4
%8 = call i32 @writeToDeviceForRead(i32 %6, i32 %7)
%9 = load i32, i32* %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = load i32, i32* %4
%12 = add nsw i32 %11, 27
%13 = trunc i32 %12 to i8
%14 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
store i8 %13, i8* %14
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%17 = call i32 @read(i32 %15, i8* %16, i32 1)
%18 = icmp ne i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %28
22: ; preds = %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %22, %19
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"Reading from reg %i\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Can't write to device\0A\00"
@.str.3 = [18 x i8] c"Read %i from buf\0A\00"
@str = [18 x i8] c"asdlfkjasldfjlksd\00"
define void @readFromDevice(i32 %0, i32 %1) {
%3 = alloca [1 x i8]
%4 = tail call i32 @writeToDeviceForRead(i32 %0, i32 %1)
%5 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = trunc i32 %1 to i8
%8 = add i8 %7, 27
store i8 %8, i8* %5
%9 = call i32 @read(i32 %0, i8* %5, i32 1)
%10 = icmp eq i32 %9, 1
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %2
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%16 = load i8, i8* %5
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %14, %11
ret void
}