#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ write(int, char const *, scalar_t__);
int gpio_omap_mux_setup(const char *omap_pin0_name, const char *mode) {
  int fd;
  char buf[64];
  snprintf(buf, sizeof(buf),
           "/sys/kernel/debug/omap_mux/"
           "%s",
           omap_pin0_name);
  fd = open(buf, O_WRONLY);
  if (fd < 0) {
    perror("failed to open OMAP_MUX");
    return fd;
  }
  write(fd, mode, strlen(mode) + 1);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<gpio_omap_mux_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x40,%esi
lea    0xe7c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x60(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bf <gpio_omap_mux_setup+0x5f>
lea    0xe6f(%rip),%rdi
call   1080 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <gpio_omap_mux_setup+0x98>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpio_omap_mux_setup>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %rdi,%rcx
lea    0xe8d(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x40,%esi
call   1050 <snprintf@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11c2 <gpio_omap_mux_setup+0x62>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe55(%rip),%rdi
call   1080 <perror@plt>
jmp    11b9 <gpio_omap_mux_setup+0x59>

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/kernel/debug/omap_mux/%s\00"
@O_WRONLY = global i32 0
@.str.1 = [24 x i8] c"failed to open OMAP_MUX\00"
define i32 @gpio_omap_mux_setup(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [64 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%9 = load i8*, i8** %4
%10 = call i32 @snprintf(i8* %8, i32 64, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%12 = load i32, i32* @O_WRONLY
%13 = call i32 @open(i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %28
19: ; preds = %2
%20 = load i32, i32* %6
%21 = load i8*, i8** %5
%22 = load i8*, i8** %5
%23 = call i64 @strlen(i8* %22)
%24 = add nsw i64 %23, 1
%25 = call i32 @write(i32 %20, i8* %21, i64 %24)
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %19, %16
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/kernel/debug/omap_mux/%s\00"
@O_WRONLY = global i32 0
@.str.1 = [24 x i8] c"failed to open OMAP_MUX\00"
define i32 @gpio_omap_mux_setup(i8* %0, i8* nocapture %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = call i32 @snprintf(i8* %4, i32 64, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @O_WRONLY
%7 = call i32 @open(i8* %4, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %16
11: ; preds = %2
%12 = call i64 @strlen(i8* dereferenceable(1) %1)
%13 = add nsw i64 %12, 1
%14 = call i32 @write(i32 %7, i8* %1, i64 %13)
%15 = call i32 @close(i32 %7)
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ %7, %9 ], [ 0, %11 ]
ret i32 %17
}