#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ gpio_direction(int, int /*<<< orphan*/);
int /*<<< orphan*/ gpio_done();
int /*<<< orphan*/ gpio_export(int);
int /*<<< orphan*/ gpio_init();
int /*<<< orphan*/ gpio_poll(int, int, int);
int gpio_read(int);
int /*<<< orphan*/ gpio_unexport(int);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ warning(char *, char *, char *, char *);
int task_gpio_test_poll(int argc, char *argv[]) {
  int pin, timeout;
  if (argc != 5) {
    warning("usage: %s %s %s <GPIO pin> <poll timeout in milliseconds>\n",
            argv[0], argv[1], argv[2]);
    return EXIT_FAILURE;
  }
  pin = atoi(argv[3]);
  timeout = atoi(argv[4]);
  gpio_init();
  gpio_export(pin);
  while (1) {
    printf("%s: switching to input on pin %d and polling\n", argv[0], pin);
    gpio_direction(pin, 0);
    printf("%s: pin %d = %d\n", argv[0], pin, gpio_read(pin));
    printf("%s: non-blocking poll\n", argv[0]);
    gpio_poll(pin, 0, 3);
    printf("%s: pin %d = %d\n", argv[0], pin, gpio_read(pin));
    printf("%s: polling for %d ms\n", argv[0], timeout);
    gpio_poll(pin, timeout, 3);
    printf("%s: pin %d = %d\n", argv[0], pin, gpio_read(pin));
  }
  gpio_unexport(pin);
  gpio_done();
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<task_gpio_test_poll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x4(%rbp)
je     11cb <task_gpio_test_poll+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe49(%rip),%rdi
call   1040 <warning@plt>
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <gpio_init@plt>
mov    -0x14(%rbp),%edi
call   1060 <gpio_export@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1080 <gpio_direction@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <gpio_read@plt>
mov    -0x48(%rbp),%rsi
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <gpio_poll@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <gpio_read@plt>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%edx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    $0x3,%edx
call   1030 <gpio_poll@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <gpio_read@plt>
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11fa <task_gpio_test_poll+0x7a>

x86 assembly (clang, -O2):
<task_gpio_test_poll>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
cmp    $0x5,%edi
jne    1284 <task_gpio_test_poll+0x104>
mov    0x18(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x20(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   10a0 <gpio_init@plt>
mov    %ebp,%edi
call   1060 <gpio_export@plt>
lea    0xea6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%rsi
lea    0xe61(%rip),%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1080 <gpio_direction@plt>
mov    (%r15),%r13
mov    %ebp,%edi
call   1070 <gpio_read@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%rsi
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0x3,%edx
call   1030 <gpio_poll@plt>
mov    (%r15),%rbx
mov    %ebp,%edi
call   1070 <gpio_read@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%r15),%rsi
lea    0xe46(%rip),%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
mov    $0x3,%edx
call   1030 <gpio_poll@plt>
mov    (%r15),%rbx
mov    %ebp,%edi
call   1070 <gpio_read@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    11d0 <task_gpio_test_poll+0x50>
mov    (%r15),%rsi
mov    0x8(%r15),%rdx
mov    0x10(%r15),%rcx
lea    0xd6a(%rip),%rdi
call   1040 <warning@plt>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"usage: %s %s %s <GPIO pin> <poll timeout in milliseconds>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [46 x i8] c"%s: switching to input on pin %d and polling\0A\00"
@.str.2 = [17 x i8] c"%s: pin %d = %d\0A\00"
@.str.3 = [23 x i8] c"%s: non-blocking poll\0A\00"
@.str.4 = [23 x i8] c"%s: polling for %d ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @task_gpio_test_poll(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 5
br i1 %8, label %9, label %21
9: ; preds = %2
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @warning(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %15, i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
ret i32 %20
21: ; preds = %2
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %5
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 4
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %6
%30 = call i32 (...) @gpio_init()
%31 = load i32, i32* %5
%32 = call i32 @gpio_export(i32 %31)
br label %33
33: ; preds = %21, %33
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = load i32, i32* %5
%38 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32 %37)
%39 = load i32, i32* %5
%40 = call i32 @gpio_direction(i32 %39, i32 0)
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = load i32, i32* %5
%45 = load i32, i32* %5
%46 = call i32 @gpio_read(i32 %45)
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %43, i32 %44, i32 %46)
%48 = load i8**, i8*** %4
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = load i32, i32* %5
%53 = call i32 @gpio_poll(i32 %52, i32 0, i32 3)
%54 = load i8**, i8*** %4
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = load i32, i32* %5
%58 = load i32, i32* %5
%59 = call i32 @gpio_read(i32 %58)
%60 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %56, i32 %57, i32 %59)
%61 = load i8**, i8*** %4
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = load i32, i32* %6
%65 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %63, i32 %64)
%66 = load i32, i32* %5
%67 = load i32, i32* %6
%68 = call i32 @gpio_poll(i32 %66, i32 %67, i32 3)
%69 = load i8**, i8*** %4
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = load i32, i32* %5
%73 = load i32, i32* %5
%74 = call i32 @gpio_read(i32 %73)
%75 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %71, i32 %72, i32 %74)
br label %33
}

LLVM IR (-O2):
@.str = [59 x i8] c"usage: %s %s %s <GPIO pin> <poll timeout in milliseconds>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [46 x i8] c"%s: switching to input on pin %d and polling\0A\00"
@.str.2 = [17 x i8] c"%s: pin %d = %d\0A\00"
@.str.3 = [23 x i8] c"%s: non-blocking poll\0A\00"
@.str.4 = [23 x i8] c"%s: polling for %d ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @task_gpio_test_poll(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32 @warning(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %7, i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
ret i32 %11
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 3
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 (...) @gpio_init()
%20 = tail call i32 @gpio_export(i32 %15)
br label %21
21: ; preds = %21, %12
%22 = load i8*, i8** %1
%23 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %15)
%24 = tail call i32 @gpio_direction(i32 %15, i32 0)
%25 = load i8*, i8** %1
%26 = tail call i32 @gpio_read(i32 %15)
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %15, i32 %26)
%28 = load i8*, i8** %1
%29 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %28)
%30 = tail call i32 @gpio_poll(i32 %15, i32 0, i32 3)
%31 = load i8*, i8** %1
%32 = tail call i32 @gpio_read(i32 %15)
%33 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %31, i32 %15, i32 %32)
%34 = load i8*, i8** %1
%35 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 %18)
%36 = tail call i32 @gpio_poll(i32 %15, i32 %18, i32 3)
%37 = load i8*, i8** %1
%38 = tail call i32 @gpio_read(i32 %15)
%39 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %15, i32 %38)
br label %21
}