#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_RDWR;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void main() {
  int fd = 0;
  char *dev = "/dev/psdev";
  fd = open(dev, O_RDWR);
  printf("fd=%d", fd);
  char *buf = "This is a test string";
  write(fd, buf, strlen(buf));
  lseek(fd, 5, SEEK_CUR);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1060 <lseek@plt>
mov    -0x4(%rbp),%edi
call   1070 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebx
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
lea    0xe81(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x5,%esi
call   1060 <lseek@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <close@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/psdev\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"fd=%d\00"
@.str.2 = [22 x i8] c"This is a test string\00"
@SEEK_CUR = global i32 0
define void @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
store i32 0, i32* %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = load i8*, i8** %2
%5 = load i32, i32* @O_RDWR
%6 = call i32 @open(i8* %4, i32 %5)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %7)
store i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8** %3
%9 = load i32, i32* %1
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @write(i32 %9, i8* %10, i32 %12)
%14 = load i32, i32* %1
%15 = load i32, i32* @SEEK_CUR
%16 = call i32 @lseek(i32 %14, i32 5, i32 %15)
%17 = load i32, i32* %1
%18 = call i32 @close(i32 %17)
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/psdev\00"
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"fd=%d\00"
@.str.2 = [22 x i8] c"This is a test string\00"
@SEEK_CUR = global i32 0
define void @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%5 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @SEEK_CUR
%7 = tail call i32 @lseek(i32 %2, i32 5, i32 %6)
%8 = tail call i32 @close(i32 %2)
ret void
}