#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*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argv[1] == NULL) {
    printf("%s: <string>\n", argv[0]);
    exit(0);
  }
  int fd = open("/dev/upcase", O_RDWR);
  write(fd, argv[1], strlen(argv[1]));
  read(fd, argv[1], strlen(argv[1]));
  printf("%s\n", argv[1]);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    11af <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe4f(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1070 <read@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdea(%rip),%rdi
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmpq   $0x0,0x8(%rsi)
je     11e7 <main+0x77>
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
lea    0xe80(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%r14d
mov    0x8(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x8(%rbx),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1070 <read@plt>
mov    0x8(%rbx),%rsi
lea    0xe47(%rip),%rdi
call   1050 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe0f(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"%s: <string>\0A\00"
@.str.1 = [12 x i8] c"/dev/upcase\00"
@O_RDWR = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 1
%9 = load i8*, i8** %8
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = load i32, i32* @O_RDWR
%19 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @write(i32 %20, i8* %23, i32 %27)
%29 = load i32, i32* %6
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = call i32 @read(i32 %29, i8* %32, i32 %36)
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = load i32, i32* %6
%43 = call i32 @close(i32 %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"%s: <string>\0A\00"
@.str.1 = [12 x i8] c"/dev/upcase\00"
@O_RDWR = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = load i32, i32* @O_RDWR
%12 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %3
%14 = tail call i32 @strlen(i8* %13)
%15 = tail call i32 @write(i32 %12, i8* %13, i32 %14)
%16 = load i8*, i8** %3
%17 = tail call i32 @strlen(i8* %16)
%18 = tail call i32 @read(i32 %12, i8* %16, i32 %17)
%19 = load i8*, i8** %3
%20 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = tail call i32 @close(i32 %12)
ret i32 0
}